From 10ce2b690c6dad8d2e089940f4d82b82380ff2af Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Oct 2014 18:21:10 -0700 Subject: [PATCH] providers/aws: retry deleting security group for some time [GH-436] --- CHANGELOG.md | 3 +++ .../providers/aws/resource_aws_security_group.go | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf9e9f55..53a1a080e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ BUG FIXES: the correct data and don't incorrectly recreate themselves. [GH-425] * providers/aws: Fix case where ELB would incorrectly plan to modify listeners (with the same data) in some cases. + * providers/aws: Retry deleting security groups for some amount of time + if there is a dependency violation since it is probably just eventual + consistency. [GH-436] ## 0.3.0 (October 14, 2014) diff --git a/builtin/providers/aws/resource_aws_security_group.go b/builtin/providers/aws/resource_aws_security_group.go index 88627a0b8..ffadad4ef 100644 --- a/builtin/providers/aws/resource_aws_security_group.go +++ b/builtin/providers/aws/resource_aws_security_group.go @@ -235,15 +235,17 @@ func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Security Group destroy: %v", d.Id()) - _, err := ec2conn.DeleteSecurityGroup(ec2.SecurityGroup{Id: d.Id()}) - if err != nil { - ec2err, ok := err.(*ec2.Error) - if ok && ec2err.Code == "InvalidGroup.NotFound" { - return nil + return resource.Retry(5 * time.Minute, func() error { + _, err := ec2conn.DeleteSecurityGroup(ec2.SecurityGroup{Id: d.Id()}) + if err != nil { + ec2err, ok := err.(*ec2.Error) + if ok && ec2err.Code == "InvalidGroup.NotFound" { + return nil + } } - } - return err + return err + }) } func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {