Merge pull request #449 from pmoust/subnet-destroy-retry

providers/aws: retry destroying subnet for some time [GH-449]
This commit is contained in:
Mitchell Hashimoto 2014-10-18 10:56:21 -07:00
commit 6eb409c00e
2 changed files with 19 additions and 8 deletions

View File

@ -20,6 +20,9 @@ BUG FIXES:
* providers/aws: Retry deleting security groups for some amount of time
if there is a dependency violation since it is probably just eventual
consistency. [GH-436]
* providers/aws: Retry deleting subnet for some amount of time if there is a
dependency violation since probably asynchronous destroy events take
place still. [GH-449]
* providers/aws: Drain autoscale groups before deleting. [GH-435]
* providers/aws: Fix crash case if launch config is manually deleted. [GH-421]

View File

@ -88,18 +88,26 @@ func resource_aws_subnet_destroy(
ec2conn := p.ec2conn
log.Printf("[INFO] Deleting Subnet: %s", s.ID)
f := func() error {
return resource.Retry(5*time.Minute, func() error {
_, err := ec2conn.DeleteSubnet(s.ID)
return err
}
if err := resource.Retry(10*time.Second, f); err != nil {
ec2err, ok := err.(*ec2.Error)
if ok && ec2err.Code == "InvalidSubnetID.NotFound" {
return nil
if err != nil {
ec2err, ok := err.(*ec2.Error)
if !ok {
return err
}
switch ec2err.Code {
case "InvalidSubnetID.NotFound":
return nil
case "DependencyViolation":
return err // retry
default:
return resource.RetryError{err}
}
}
return fmt.Errorf("Error deleting subnet: %s", err)
}
})
// Wait for the Subnet to actually delete
log.Printf("[DEBUG] Waiting for subnet (%s) to delete", s.ID)