Skip to content

Commit

Permalink
Cause node pool to be written to statefile even if creation fails. (#…
Browse files Browse the repository at this point in the history
…3476) (#2038)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 6, 2020
1 parent b39e73a commit 2dce264
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/3476.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: Fix occasional error with `container_node_pool` partially-successful creations not being recorded if an error occurs on the GCP side.
```
7 changes: 5 additions & 2 deletions google-beta/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e
timeout := d.Timeout(schema.TimeoutCreate)
startTime := time.Now()

// Set the ID before we attempt to create - that way, if we receive an error but
// the resource is created anyway, it will be refreshed on the next call to
// apply.
d.SetId(fmt.Sprintf("projects/%s/locations/%s/clusters/%s/nodePools/%s", nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, nodePool.Name))

var operation *containerBeta.Operation
err = resource.Retry(timeout, func() *resource.RetryError {
operation, err = config.clientContainerBeta.
Expand All @@ -287,8 +292,6 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e
}
timeout -= time.Since(startTime)

d.SetId(fmt.Sprintf("projects/%s/locations/%s/clusters/%s/nodePools/%s", nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, nodePool.Name))

waitErr := containerOperationWait(config,
operation, nodePoolInfo.project,
nodePoolInfo.location, "creating GKE NodePool", timeout)
Expand Down

0 comments on commit 2dce264

Please sign in to comment.