Skip to content

Commit

Permalink
Merge pull request #449 from pmoust/subnet-destroy-retry
Browse files Browse the repository at this point in the history
providers/aws: retry destroying subnet for some time [GH-449]
  • Loading branch information
mitchellh committed Oct 18, 2014
2 parents 4d2ecab + d6d8d0f commit 6eb409c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
24 changes: 16 additions & 8 deletions builtin/providers/aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6eb409c

Please sign in to comment.