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

resource/aws_network_interface_sg_attachment: Properly handle InvalidNetworkInterfaceID.NotFound errors #6048

Merged
merged 1 commit into from
Oct 3, 2018
Merged
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
21 changes: 17 additions & 4 deletions aws/resource_aws_network_interface_sg_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func resourceAwsNetworkInterfaceSGAttachmentRead(d *schema.ResourceData, meta in
conn := meta.(*AWSClient).ec2conn

iface, err := fetchNetworkInterface(conn, interfaceID)

if isAWSErr(err, "InvalidNetworkInterfaceID.NotFound", "") {
log.Printf("[WARN] EC2 Network Interface (%s) not found, removing from state", interfaceID)
d.SetId("")
return nil
}

if err != nil {
return err
}
Expand Down Expand Up @@ -108,15 +115,16 @@ func resourceAwsNetworkInterfaceSGAttachmentDelete(d *schema.ResourceData, meta
conn := meta.(*AWSClient).ec2conn

iface, err := fetchNetworkInterface(conn, interfaceID)
if err != nil {
return err

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

if err := delSGFromENI(conn, sgID, iface); err != nil {
if err != nil {
return err
}

return nil
return delSGFromENI(conn, sgID, iface)
}

// fetchNetworkInterface is a utility function used by Read and Delete to fetch
Expand Down Expand Up @@ -154,6 +162,11 @@ func delSGFromENI(conn *ec2.EC2, sgID string, iface *ec2.NetworkInterface) error
}

_, err := conn.ModifyNetworkInterfaceAttribute(params)

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

return err
}

Expand Down
Loading