|
9 | 9 |
|
10 | 10 | "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" |
11 | 11 | "github.com/hashicorp/terraform-plugin-framework/diag" |
12 | | - "github.com/hashicorp/terraform-plugin-framework/path" |
13 | 12 | "github.com/hashicorp/terraform-plugin-framework/resource" |
14 | 13 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" |
15 | 14 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" |
@@ -221,6 +220,15 @@ func (g *gitResource) Create(ctx context.Context, req resource.CreateRequest, re |
221 | 220 | ctx = core.LogResponse(ctx) |
222 | 221 |
|
223 | 222 | gitInstanceId := *gitInstanceResp.Id |
| 223 | + // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler |
| 224 | + ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ |
| 225 | + "project_id": projectId, |
| 226 | + "instance_id": gitInstanceId, |
| 227 | + }) |
| 228 | + if resp.Diagnostics.HasError() { |
| 229 | + return |
| 230 | + } |
| 231 | + |
224 | 232 | _, err = wait.CreateGitInstanceWaitHandler(ctx, g.client, projectId, gitInstanceId).WaitWithContext(ctx) |
225 | 233 | if err != nil { |
226 | 234 | core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating git instance", fmt.Sprintf("Git instance creation waiting: %v", err)) |
@@ -345,13 +353,11 @@ func (g *gitResource) ImportState(ctx context.Context, req resource.ImportStateR |
345 | 353 | ) |
346 | 354 | return |
347 | 355 | } |
348 | | - |
349 | | - projectId := idParts[0] |
350 | | - instanceId := idParts[1] |
351 | | - |
352 | 356 | // Set the project ID and instance ID attributes in the state. |
353 | | - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), projectId)...) |
354 | | - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), instanceId)...) |
| 357 | + ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]interface{}{ |
| 358 | + "project_id": idParts[0], |
| 359 | + "instance_id": idParts[1], |
| 360 | + }) |
355 | 361 | tflog.Info(ctx, "Git instance state imported") |
356 | 362 | } |
357 | 363 |
|
|
0 commit comments