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

Revert "provider/aws: Fix dependency violation with subnets and security groups" #1368

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions builtin/providers/aws/resource_aws_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{})
switch ec2err.Code {
case "InvalidInternetGatewayID.NotFound":
return nil
case "DependencyViolation":
return err // retry
}

return resource.RetryError{Err: err}
Expand Down Expand Up @@ -232,10 +230,11 @@ func detachIGStateRefreshFunc(conn *ec2.EC2, instanceID, vpcID string) resource.
return nil, "Not Found", err
} else if ec2err.Code == "Gateway.NotAttached" {
return "detached", "detached", nil
} else if ec2err.Code == "DependencyViolation" {
return nil, "detaching", nil
}
}

log.Printf("Error on detachIGStateRefreshFunc: %#v", err)
return nil, "", err
}
// DetachInternetGateway only returns an error, so if it's nil, assume we're
// detached
Expand Down
31 changes: 10 additions & 21 deletions builtin/providers/aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,30 +261,19 @@ func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er

log.Printf("[DEBUG] Security Group destroy: %v", d.Id())

return resource.Retry(5*time.Minute, func() error {
_, err := conn.DeleteSecurityGroup(&ec2.DeleteSecurityGroupInput{
GroupID: aws.String(d.Id()),
})
if err != nil {
ec2err, ok := err.(aws.APIError)
if !ok {
return err
}
request := &ec2.DeleteSecurityGroupInput{
GroupID: aws.String(d.Id()),
}

switch ec2err.Code {
case "InvalidGroup.NotFound":
return nil
case "DependencyViolation":
// If it is a dependency violation, we want to retry
return err
default:
// Any other error, we want to quit the retry loop immediately
return resource.RetryError{Err: err}
}
_, err := conn.DeleteSecurityGroup(request)
if err != nil {
ec2err, ok := err.(aws.APIError)
if ok && ec2err.Code == "InvalidGroup.NotFound" {
return nil
}
}

return nil
})
return err
}

func resourceAwsSecurityGroupRuleHash(v interface{}) int {
Expand Down
37 changes: 8 additions & 29 deletions builtin/providers/aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,38 +159,17 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

log.Printf("[INFO] Deleting subnet: %s", d.Id())
req := &ec2.DeleteSubnetInput{
SubnetID: aws.String(d.Id()),
}

wait := resource.StateChangeConf{
Pending: []string{"pending"},
Target: "destroyed",
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
_, err := conn.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
}
_, err := conn.DeleteSubnet(&ec2.DeleteSubnetInput{
SubnetID: aws.String(d.Id()),
})

return 42, "destroyed", nil
},
}
if err != nil {
ec2err, ok := err.(aws.APIError)
if ok && ec2err.Code == "InvalidSubnetID.NotFound" {
return nil
}

if _, err := wait.WaitForState(); err != nil {
return fmt.Errorf("Error deleting subnet: %s", err)
}

Expand Down