From 0c81a9c1082bd9f4e32c387e6a5cea1a571da2cc Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Fri, 23 Oct 2015 15:06:46 -0400 Subject: [PATCH] provider/google: Fixed timeout bug on large instance groups --- ...resource_compute_instance_group_manager.go | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_instance_group_manager.go b/builtin/providers/google/resource_compute_instance_group_manager.go index ed48b26d5..938738146 100644 --- a/builtin/providers/google/resource_compute_instance_group_manager.go +++ b/builtin/providers/google/resource_compute_instance_group_manager.go @@ -3,6 +3,7 @@ package google import ( "fmt" "log" + "strings" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" @@ -247,10 +248,32 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte return fmt.Errorf("Error deleting instance group manager: %s", err) } + currentSize := int64(d.Get("target_size").(int)) + // Wait for the operation to complete err = computeOperationWaitZone(config, op, d.Get("zone").(string), "Deleting InstanceGroupManager") - if err != nil { - return err + + for err != nil && currentSize > 0 { + if !strings.Contains(err.Error(), "timeout") { + return err; + } + + instanceGroup, err := config.clientCompute.InstanceGroups.Get( + config.Project, d.Get("zone").(string), d.Id()).Do() + + if err != nil { + return fmt.Errorf("Error getting instance group size: %s", err); + } + + if instanceGroup.Size >= currentSize { + return fmt.Errorf("Error, instance group isn't shrinking during delete") + } + + log.Printf("[INFO] timeout occured, but instance group is shrinking (%d < %d)", instanceGroup.Size, currentSize) + + currentSize = instanceGroup.Size + + err = computeOperationWaitZone(config, op, d.Get("zone").(string), "Deleting InstanceGroupManager") } d.SetId("")