Skip to content

Commit a00b046

Browse files
authored
fix(observability): timeout updating alert config (#902)
1 parent 2dda93b commit a00b046

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

  • stackit/internal/services/observability/instance

stackit/internal/services/observability/instance/resource.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88
"strings"
99

10+
"github.com/google/go-cmp/cmp"
1011
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1112

1213
observabilityUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/utils"
@@ -1094,19 +1095,40 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
10941095
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Creating API payload: %v", err))
10951096
return
10961097
}
1097-
// Update existing instance
1098-
_, err = r.client.UpdateInstance(ctx, instanceId, projectId).UpdateInstancePayload(*payload).Execute()
1099-
if err != nil {
1100-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err))
1098+
var previousState Model
1099+
diags = req.State.Get(ctx, &previousState)
1100+
resp.Diagnostics.Append(diags...)
1101+
if resp.Diagnostics.HasError() {
11011102
return
11021103
}
1103-
waitResp, err := wait.UpdateInstanceWaitHandler(ctx, r.client, instanceId, projectId).WaitWithContext(ctx)
1104+
previousStatePayload, err := toUpdatePayload(&previousState)
11041105
if err != nil {
1105-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err))
1106+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Creating previous state payload: %v", err))
11061107
return
11071108
}
1109+
var instance *observability.GetInstanceResponse
1110+
// This check is required, because when values should be updated, that needs to be updated via a different endpoint, the waiter will run into a timeout
1111+
if !cmp.Equal(previousStatePayload, payload) {
1112+
// Update existing instance
1113+
_, err = r.client.UpdateInstance(ctx, instanceId, projectId).UpdateInstancePayload(*payload).Execute()
1114+
if err != nil {
1115+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err))
1116+
return
1117+
}
1118+
instance, err = wait.UpdateInstanceWaitHandler(ctx, r.client, instanceId, projectId).WaitWithContext(ctx)
1119+
if err != nil {
1120+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err))
1121+
return
1122+
}
1123+
} else {
1124+
instance, err = r.client.GetInstanceExecute(ctx, instanceId, projectId)
1125+
if err != nil {
1126+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance read: %v", err))
1127+
return
1128+
}
1129+
}
11081130

1109-
err = mapFields(ctx, waitResp, &model)
1131+
err = mapFields(ctx, instance, &model)
11101132
if err != nil {
11111133
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Processing API payload: %v", err))
11121134
return

0 commit comments

Comments
 (0)