From 8650d99e43d81508a1a2063b749fea26ad7f21ac Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 9 Jul 2019 22:15:16 +0000 Subject: [PATCH] Don't clear cluster from state if cleanup fails Signed-off-by: Modular Magician --- google/resource_container_cluster.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 508c77cb684..4317178fc64 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -875,23 +875,23 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er d.SetId(clusterName) // Wait until it's created - timeoutInMinutes := int(d.Timeout(schema.TimeoutCreate).Minutes()) waitErr := containerOperationWait(config, op, project, location, "creating GKE cluster", timeoutInMinutes) if waitErr != nil { // Try a GET on the cluster so we can see the state in debug logs. This will help classify error states. _, getErr := config.clientContainerBeta.Projects.Locations.Clusters.Get(containerClusterFullName(project, location, clusterName)).Do() if getErr != nil { - // Make errcheck happy log.Printf("[WARN] Cluster %s was created in an error state and not found", clusterName) + d.SetId("") } if deleteErr := cleanFailedContainerCluster(d, meta); deleteErr != nil { log.Printf("[WARN] Unable to clean up cluster from failed creation: %s", deleteErr) + // Leave ID set as the cluster likely still exists and should not be removed from state yet. } else { log.Printf("[WARN] Verified failed creation of cluster %s was cleaned up", d.Id()) + d.SetId("") } // The resource didn't actually create - d.SetId("") return waitErr }