From 188e60c54e6faf8f4d5d6b1eea695499610ee9ac Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 17 Jan 2018 14:41:35 -0500 Subject: [PATCH] resource/aws_cloudfront_distribution: Retry deletion on DistributionNotDisabled --- aws/resource_aws_cloudfront_distribution.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_cloudfront_distribution.go b/aws/resource_aws_cloudfront_distribution.go index eeda932850a..e7ecb3de465 100644 --- a/aws/resource_aws_cloudfront_distribution.go +++ b/aws/resource_aws_cloudfront_distribution.go @@ -666,9 +666,19 @@ func resourceAwsCloudFrontDistributionDelete(d *schema.ResourceData, meta interf IfMatch: aws.String(d.Get("etag").(string)), } - _, err = conn.DeleteDistribution(params) + // Eventual consistency for "deployed" state + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + _, err := conn.DeleteDistribution(params) + if err != nil { + if isAWSErr(err, cloudfront.ErrCodeDistributionNotDisabled, "The distribution you are trying to delete has not been disabled.") { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) if err != nil { - return err + return fmt.Errorf("CloudFront Distribution %s cannot be deleted: %s", d.Id(), err) } // Done