Skip to content

Commit

Permalink
The ENIs associated with lambda functions sometimes fail to delete. This
Browse files Browse the repository at this point in the history
applies the deleteLingeringLambdaENIs as well as the associated timeouts
from resource_aws_security_group to resource_aws_subnet.
  • Loading branch information
mmarod authored and jen20 committed Sep 24, 2018
1 parent 2cead4b commit 1ca811e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er

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

if err := deleteLingeringLambdaENIs(conn, d); err != nil {
if err := deleteLingeringLambdaENIs(conn, d, "group-id"); err != nil {
return fmt.Errorf("Failed to delete Lambda ENIs: %s", err)
}

Expand Down Expand Up @@ -1398,12 +1398,12 @@ func sgProtocolIntegers() map[string]int {

// The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while
// which would prevent SGs attached to such ENIs from being destroyed
func deleteLingeringLambdaENIs(conn *ec2.EC2, d *schema.ResourceData) error {
func deleteLingeringLambdaENIs(conn *ec2.EC2, d *schema.ResourceData, filterName string) error {
// Here we carefully find the offenders
params := &ec2.DescribeNetworkInterfacesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("group-id"),
Name: aws.String(filterName),
Values: []*string{aws.String(d.Id())},
},
{
Expand Down
10 changes: 10 additions & 0 deletions aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func resourceAwsSubnet() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},

SchemaVersion: 1,
MigrateState: resourceAwsSubnetMigrateState,

Expand Down Expand Up @@ -303,6 +308,11 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

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

if err := deleteLingeringLambdaENIs(conn, d, "subnet-id"); err != nil {
return fmt.Errorf("Failed to delete Lambda ENIs: %s", err)
}

req := &ec2.DeleteSubnetInput{
SubnetId: aws.String(d.Id()),
}
Expand Down

0 comments on commit 1ca811e

Please sign in to comment.