Merge remote-tracking branch 'upstream/master'

* upstream/master:
  provider/aws: Fix dependency violation with subnets and security groups
This commit is contained in:
Clint Shryock 2015-03-19 16:01:15 -05:00
commit 1ccfcb5e3d
1 changed files with 29 additions and 8 deletions

View File

@ -157,17 +157,38 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2conn
log.Printf("[INFO] Deleting subnet: %s", d.Id()) log.Printf("[INFO] Deleting subnet: %s", d.Id())
req := &ec2.DeleteSubnetRequest{
err := ec2conn.DeleteSubnet(&ec2.DeleteSubnetRequest{
SubnetID: aws.String(d.Id()), SubnetID: aws.String(d.Id()),
}) }
if err != nil { wait := resource.StateChangeConf{
ec2err, ok := err.(aws.APIError) Pending: []string{"pending"},
if ok && ec2err.Code == "InvalidSubnetID.NotFound" { Target: "destroyed",
return nil Timeout: 5 * time.Minute,
} MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
err := ec2conn.DeleteSubnet(req)
if err != nil {
if apiErr, ok := err.(aws.APIError); ok {
if apiErr.Code == "DependencyViolation" {
// There is some pending operation, so just retry
// in a bit.
return 42, "pending", nil
}
if apiErr.Code == "InvalidSubnetID.NotFound" {
return 42, "destroyed", nil
}
}
return 42, "failure", err
}
return 42, "destroyed", nil
},
}
if _, err := wait.WaitForState(); err != nil {
return fmt.Errorf("Error deleting subnet: %s", err) return fmt.Errorf("Error deleting subnet: %s", err)
} }