|
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" |
@@ -220,7 +219,21 @@ func (g *gitResource) Create(ctx context.Context, req resource.CreateRequest, re |
220 | 219 |
|
221 | 220 | ctx = core.LogResponse(ctx) |
222 | 221 |
|
| 222 | + if gitInstanceResp.Id == nil { |
| 223 | + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating git instance", "Got empty git instance id") |
| 224 | + return |
| 225 | + } |
| 226 | + |
223 | 227 | gitInstanceId := *gitInstanceResp.Id |
| 228 | + // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler |
| 229 | + ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ |
| 230 | + "project_id": projectId, |
| 231 | + "instance_id": gitInstanceId, |
| 232 | + }) |
| 233 | + if resp.Diagnostics.HasError() { |
| 234 | + return |
| 235 | + } |
| 236 | + |
224 | 237 | _, err = wait.CreateGitInstanceWaitHandler(ctx, g.client, projectId, gitInstanceId).WaitWithContext(ctx) |
225 | 238 | if err != nil { |
226 | 239 | core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating git instance", fmt.Sprintf("Git instance creation waiting: %v", err)) |
@@ -345,13 +358,11 @@ func (g *gitResource) ImportState(ctx context.Context, req resource.ImportStateR |
345 | 358 | ) |
346 | 359 | return |
347 | 360 | } |
348 | | - |
349 | | - projectId := idParts[0] |
350 | | - instanceId := idParts[1] |
351 | | - |
352 | 361 | // 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)...) |
| 362 | + ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]interface{}{ |
| 363 | + "project_id": idParts[0], |
| 364 | + "instance_id": idParts[1], |
| 365 | + }) |
355 | 366 | tflog.Info(ctx, "Git instance state imported") |
356 | 367 | } |
357 | 368 |
|
|
0 commit comments