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

ec2: Prevent "InvalidNetworkInterfaceID.NotFound" errors in deleteLingeringLambdaENIs #6037

Merged
merged 1 commit into from
Oct 2, 2018
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
18 changes: 17 additions & 1 deletion aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,11 @@ func deleteLingeringLambdaENIs(conn *ec2.EC2, d *schema.ResourceData, filterName
},
}
networkInterfaceResp, err := conn.DescribeNetworkInterfaces(params)

if isAWSErr(err, "InvalidNetworkInterfaceID.NotFound", "") {
return nil
}

if err != nil {
return err
}
Expand All @@ -1426,6 +1431,10 @@ func deleteLingeringLambdaENIs(conn *ec2.EC2, d *schema.ResourceData, filterName
}
_, detachNetworkInterfaceErr := conn.DetachNetworkInterface(detachNetworkInterfaceParams)

if isAWSErr(detachNetworkInterfaceErr, "InvalidNetworkInterfaceID.NotFound", "") {
return nil
}

if detachNetworkInterfaceErr != nil {
return detachNetworkInterfaceErr
}
Expand All @@ -1448,6 +1457,10 @@ func deleteLingeringLambdaENIs(conn *ec2.EC2, d *schema.ResourceData, filterName
}
_, deleteNetworkInterfaceErr := conn.DeleteNetworkInterface(deleteNetworkInterfaceParams)

if isAWSErr(deleteNetworkInterfaceErr, "InvalidNetworkInterfaceID.NotFound", "") {
return nil
}

if deleteNetworkInterfaceErr != nil {
return deleteNetworkInterfaceErr
}
Expand All @@ -1464,8 +1477,11 @@ func networkInterfaceAttachedRefreshFunc(conn *ec2.EC2, id string) resource.Stat
}
describeResp, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request)

if isAWSErr(err, "InvalidNetworkInterfaceID.NotFound", "") {
return 42, "false", nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 42 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jen20 something I don't necessarily agree with, but an existing convention that is a workaround for return nil, X, nil causing WaitForState() to treat the refresh as a missing resource and automatically retry without exiting the WaitForState() since Target has a value: https://github.com/hashicorp/terraform/blob/master/helper/resource/state.go#L115-L137

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, the second part was what I assumed but thought I would clarify! Is it worth introducing a constant here to make the intent clearer?

}

if err != nil {
log.Printf("[ERROR] Could not find network interface %s. %s", id, err)
return nil, "", err
}

Expand Down