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

r/internet_gateway: Retry properly on DependencyViolation #1021

Merged
merged 1 commit into from
Jul 8, 2017
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
35 changes: 31 additions & 4 deletions aws/resource_aws_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,50 @@ func detachIGStateRefreshFunc(conn *ec2.EC2, gatewayID, vpcID string) resource.S
switch ec2err.Code() {
case "InvalidInternetGatewayID.NotFound":
log.Printf("[TRACE] Error detaching Internet Gateway '%s' from VPC '%s': %s", gatewayID, vpcID, err)
return nil, "Not Found", nil
return nil, "", nil

case "Gateway.NotAttached":
return "detached", "detached", nil
return 42, "detached", nil

case "DependencyViolation":
return nil, "detaching", nil
// This can be caused by associated public IPs left (e.g. by ELBs)
// and here we find and log which ones are to blame
out, err := findPublicNetworkInterfacesForVpcID(conn, vpcID)
if err != nil {
return 42, "detaching", err
}
if len(out.NetworkInterfaces) > 0 {
log.Printf("[DEBUG] Waiting for the following %d ENIs to be gone: %s",
len(out.NetworkInterfaces), out.NetworkInterfaces)
}

return 42, "detaching", nil
}
}
return 42, "", err
}

// DetachInternetGateway only returns an error, so if it's nil, assume we're
// detached
return "detached", "detached", nil
return 42, "detached", nil
}
}

func findPublicNetworkInterfacesForVpcID(conn *ec2.EC2, vpcID string) (*ec2.DescribeNetworkInterfacesOutput, error) {
return conn.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(vpcID)},
},
{
Name: aws.String("association.public-ip"),
Values: []*string{aws.String("*")},
},
},
})
}

// IGStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// an internet gateway.
func IGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
Expand Down