From b3eefecc05e66b6870129a4b39a80eaa71dbb94d Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 8 May 2017 11:15:12 +0200 Subject: [PATCH] provider/aws: Retry deletion of AWSConfig Rule on ResourceInUseException (#14269) --- .../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 a5c86c334..cc18d1995 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)