diff --git a/third_party/terraform/resources/resource_container_node_pool.go.erb b/third_party/terraform/resources/resource_container_node_pool.go.erb index f3bf1f17138e..de22d19c3512 100644 --- a/third_party/terraform/resources/resource_container_node_pool.go.erb +++ b/third_party/terraform/resources/resource_container_node_pool.go.erb @@ -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. @@ -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)