provider/google: Fixed timeout bug on large instance groups

This commit is contained in:
Lars Wander 2015-10-23 15:06:46 -04:00
parent c817e7c765
commit 0c81a9c108
1 changed files with 25 additions and 2 deletions

View File

@ -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")
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 err
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("")