Skip to content

Commit 2dce264

Browse files
Cause node pool to be written to statefile even if creation fails. (#3476) (#2038)
Signed-off-by: Modular Magician <[email protected]>
1 parent b39e73a commit 2dce264

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changelog/3476.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: Fix occasional error with `container_node_pool` partially-successful creations not being recorded if an error occurs on the GCP side.
3+
```

google-beta/resource_container_node_pool.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e
267267
timeout := d.Timeout(schema.TimeoutCreate)
268268
startTime := time.Now()
269269

270+
// Set the ID before we attempt to create - that way, if we receive an error but
271+
// the resource is created anyway, it will be refreshed on the next call to
272+
// apply.
273+
d.SetId(fmt.Sprintf("projects/%s/locations/%s/clusters/%s/nodePools/%s", nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, nodePool.Name))
274+
270275
var operation *containerBeta.Operation
271276
err = resource.Retry(timeout, func() *resource.RetryError {
272277
operation, err = config.clientContainerBeta.
@@ -287,8 +292,6 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e
287292
}
288293
timeout -= time.Since(startTime)
289294

290-
d.SetId(fmt.Sprintf("projects/%s/locations/%s/clusters/%s/nodePools/%s", nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, nodePool.Name))
291-
292295
waitErr := containerOperationWait(config,
293296
operation, nodePoolInfo.project,
294297
nodePoolInfo.location, "creating GKE NodePool", timeout)

0 commit comments

Comments
 (0)