From 24c72d0f6dbf4e52d3beb70f4d02c798a4b77d66 Mon Sep 17 00:00:00 2001 From: I584814 Date: Mon, 14 Oct 2024 11:12:11 +0000 Subject: [PATCH 1/7] error handling for timeouts --- internal/tfutils/state.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/tfutils/state.go b/internal/tfutils/state.go index bf8c05f8..e7c79c0c 100644 --- a/internal/tfutils/state.go +++ b/internal/tfutils/state.go @@ -5,6 +5,7 @@ package tfutils import ( "context" + "fmt" "log" "time" ) @@ -263,6 +264,12 @@ func (conf *StateChangeConf) WaitForStateContext(ctx context.Context) (interface } } + for _, state := range conf.Pending{ + if lastResult.State == state { + return nil, fmt.Errorf("%s","The timeout has exceeded. Try increasing the timeout for the particular operation.") + } + } + return nil, &TimeoutError{ LastError: lastResult.Error, LastState: lastResult.State, From 42cbe958bfd90f445d9df296f3cca7df4be5af0d Mon Sep 17 00:00:00 2001 From: I584814 Date: Mon, 14 Oct 2024 11:22:12 +0000 Subject: [PATCH 2/7] mofified the call for the create timeout --- internal/provider/resource_subaccount_subscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/resource_subaccount_subscription.go b/internal/provider/resource_subaccount_subscription.go index 748e1360..1dbf3474 100644 --- a/internal/provider/resource_subaccount_subscription.go +++ b/internal/provider/resource_subaccount_subscription.go @@ -316,7 +316,7 @@ func (rs *subaccountSubscriptionResource) CreateStateChange(ctx context.Context, timeoutsLocal := plan.Timeouts - createTimeout, diags := timeoutsLocal.Update(ctx, tfutils.DefaultTimeout) + createTimeout, diags := timeoutsLocal.Create(ctx, tfutils.DefaultTimeout) summary.Append(diags...) delay, minTimeout := tfutils.CalculateDelayAndMinTimeOut(createTimeout) From b153ce0091bd9cb4a3afa568ed84c818326c6876 Mon Sep 17 00:00:00 2001 From: I584814 Date: Tue, 15 Oct 2024 06:13:26 +0000 Subject: [PATCH 3/7] added check for nil response --- internal/provider/resource_subaccount_subscription.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/provider/resource_subaccount_subscription.go b/internal/provider/resource_subaccount_subscription.go index 1dbf3474..c883ee94 100644 --- a/internal/provider/resource_subaccount_subscription.go +++ b/internal/provider/resource_subaccount_subscription.go @@ -248,6 +248,10 @@ func (rs *subaccountSubscriptionResource) Create(ctx context.Context, req resour resp.Diagnostics.AddError("API Error Creating Resource Subscription (Subaccount)", fmt.Sprintf("%s", err)) } + if updatedRes == nil { + return + } + updatedPlan, diags := subaccountSubscriptionValueFrom(ctx, updatedRes.(saas_manager_service.EntitledApplicationsResponseObject)) updatedPlan.Parameters = plan.Parameters updatedPlan.Timeouts = plan.Timeouts From 9edd7cf7a6dd1762b66744e9f9a2ba40dd911f1d Mon Sep 17 00:00:00 2001 From: I584814 Date: Tue, 15 Oct 2024 06:13:55 +0000 Subject: [PATCH 4/7] reverted changes made --- internal/tfutils/state.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/tfutils/state.go b/internal/tfutils/state.go index e7c79c0c..bf8c05f8 100644 --- a/internal/tfutils/state.go +++ b/internal/tfutils/state.go @@ -5,7 +5,6 @@ package tfutils import ( "context" - "fmt" "log" "time" ) @@ -264,12 +263,6 @@ func (conf *StateChangeConf) WaitForStateContext(ctx context.Context) (interface } } - for _, state := range conf.Pending{ - if lastResult.State == state { - return nil, fmt.Errorf("%s","The timeout has exceeded. Try increasing the timeout for the particular operation.") - } - } - return nil, &TimeoutError{ LastError: lastResult.Error, LastState: lastResult.State, From 3678e77e51e1a0cf6a585b0031f29d19257f88db Mon Sep 17 00:00:00 2001 From: I584814 Date: Tue, 15 Oct 2024 06:14:29 +0000 Subject: [PATCH 5/7] added to the error message --- internal/tfutils/error.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/tfutils/error.go b/internal/tfutils/error.go index 180a3f6a..d827f0bc 100644 --- a/internal/tfutils/error.go +++ b/internal/tfutils/error.go @@ -95,7 +95,7 @@ func (e *TimeoutError) Error() string { expectedState, suffix, e.LastError) } - return fmt.Sprintf("timeout while waiting for %s%s", + return fmt.Sprintf("timeout while waiting for %s%s\ntry increasing the timeout for this particular operation", expectedState, suffix) } From 8b513225bf00fc9ca4f2d8af26bda20cb54dadf2 Mon Sep 17 00:00:00 2001 From: I584814 Date: Tue, 15 Oct 2024 08:28:39 +0000 Subject: [PATCH 6/7] error message changes --- internal/tfutils/state_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/tfutils/state_test.go b/internal/tfutils/state_test.go index 9ae18079..d736a2d7 100644 --- a/internal/tfutils/state_test.go +++ b/internal/tfutils/state_test.go @@ -177,7 +177,7 @@ func TestWaitForState_timeout(t *testing.T) { t.Fatal("Expected timeout error. No error returned.") } - expectedErr := "timeout while waiting for state to become 'running' (timeout: 1ms)" + expectedErr := "timeout while waiting for state to become 'running' (timeout: 1ms)\ntry increasing the timeout for this particular operation" if err.Error() != expectedErr { t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error()) } @@ -235,7 +235,7 @@ func TestWaitForState_cancel(t *testing.T) { t.Fatal("Expected timeout error. No error returned.") } - expectedErr := "timeout while waiting for state to become 'running'" + expectedErr := "timeout while waiting for state to become 'running' (last state: 'pending', timeout: 10ms)\ntry increasing the timeout for this particular operation" if !strings.HasPrefix(err.Error(), expectedErr) { t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error()) } @@ -322,7 +322,7 @@ func TestWaitForState_failureEmpty(t *testing.T) { if err == nil { t.Fatal("Expected timeout error. Got none.") } - expectedErr := "timeout while waiting for resource to be gone (last state: 'pending', timeout: 100ms)" + expectedErr := "timeout while waiting for resource to be gone (last state: 'pending', timeout: 100ms)\ntry increasing the timeout for this particular operation" if err.Error() != expectedErr { t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error()) } From 15849e44e3a04b981f9c072accf91962ce687608 Mon Sep 17 00:00:00 2001 From: I584814 Date: Tue, 15 Oct 2024 17:22:34 +0000 Subject: [PATCH 7/7] added return statement in other resources --- internal/provider/resource_subaccount_environment_instance.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/provider/resource_subaccount_environment_instance.go b/internal/provider/resource_subaccount_environment_instance.go index 13c06bae..7b7ba4c6 100644 --- a/internal/provider/resource_subaccount_environment_instance.go +++ b/internal/provider/resource_subaccount_environment_instance.go @@ -284,6 +284,7 @@ func (rs *subaccountEnvironmentInstanceResource) Create(ctx context.Context, req updatedRes, err := createStateConf.WaitForStateContext(ctx) if err != nil { resp.Diagnostics.AddError("API Error Creating Resource Environment Instance (Subaccount)", fmt.Sprintf("%s", err)) + return } plan, diags = subaccountEnvironmentInstanceValueFrom(ctx, updatedRes.(provisioning.EnvironmentInstanceResponseObject)) @@ -339,6 +340,7 @@ func (rs *subaccountEnvironmentInstanceResource) Update(ctx context.Context, req updatedRes, err := updateStateConf.WaitForStateContext(ctx) if err != nil { resp.Diagnostics.AddError("API Error Updating Resource Environment Instance (Subaccount)", fmt.Sprintf("%s", err)) + return } state, diags := subaccountEnvironmentInstanceValueFrom(ctx, updatedRes.(provisioning.EnvironmentInstanceResponseObject))