From d95d263c0c90841bec4a2482f3cfe9c3a59d297e Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Sat, 6 May 2017 10:02:21 +0200 Subject: [PATCH] provider/aws: Retry deletion of AWSConfig Rule on ResourceInUseException --- .../aws/resource_aws_config_config_rule.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_config_config_rule.go b/builtin/providers/aws/resource_aws_config_config_rule.go index a5c86c334e03..cc18d19956e5 100644 --- a/builtin/providers/aws/resource_aws_config_config_rule.go +++ b/builtin/providers/aws/resource_aws_config_config_rule.go @@ -242,8 +242,17 @@ func resourceAwsConfigConfigRuleDelete(d *schema.ResourceData, meta interface{}) name := d.Get("name").(string) log.Printf("[DEBUG] Deleting AWS Config config rule %q", name) - _, err := conn.DeleteConfigRule(&configservice.DeleteConfigRuleInput{ - ConfigRuleName: aws.String(name), + err := resource.Retry(2*time.Minute, func() *resource.RetryError { + _, err := conn.DeleteConfigRule(&configservice.DeleteConfigRuleInput{ + ConfigRuleName: aws.String(name), + }) + if err != nil { + if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceInUseException" { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil }) if err != nil { return fmt.Errorf("Deleting Config Rule failed: %s", err)