Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Fix dependency violation with subnets and security groups #1252

Merged
merged 1 commit into from
Mar 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions builtin/providers/aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,38 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn

log.Printf("[INFO] Deleting subnet: %s", d.Id())

err := ec2conn.DeleteSubnet(&ec2.DeleteSubnetRequest{
req := &ec2.DeleteSubnetRequest{
SubnetID: aws.String(d.Id()),
})
}

if err != nil {
ec2err, ok := err.(aws.APIError)
if ok && ec2err.Code == "InvalidSubnetID.NotFound" {
return nil
}
wait := resource.StateChangeConf{
Pending: []string{"pending"},
Target: "destroyed",
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)
}

Expand Down