Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_cloudfront_distribution: Allow create and update retries on InvalidViewerCertificate for eventual consistency issues #4698

Merged
merged 1 commit into from
Jun 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,25 @@ func resourceAwsCloudFrontDistributionCreate(d *schema.ResourceData, meta interf
},
}

resp, err := conn.CreateDistributionWithTags(params)
var resp *cloudfront.CreateDistributionWithTagsOutput
// Handle eventual consistency issues
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.CreateDistributionWithTags(params)
if err != nil {
// ACM and IAM certificate eventual consistency
// InvalidViewerCertificate: The specified SSL certificate doesn't exist, isn't in us-east-1 region, isn't valid, or doesn't include a valid certificate chain.
if isAWSErr(err, cloudfront.ErrCodeInvalidViewerCertificate, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
return fmt.Errorf("error creating CloudFront Distribution: %s", err)
}

d.SetId(*resp.Distribution.Id)
return resourceAwsCloudFrontDistributionRead(d, meta)
}
Expand Down Expand Up @@ -768,9 +783,22 @@ func resourceAwsCloudFrontDistributionUpdate(d *schema.ResourceData, meta interf
DistributionConfig: expandDistributionConfig(d),
IfMatch: aws.String(d.Get("etag").(string)),
}
_, err := conn.UpdateDistribution(params)

// Handle eventual consistency issues
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateDistribution(params)
if err != nil {
// ACM and IAM certificate eventual consistency
// InvalidViewerCertificate: The specified SSL certificate doesn't exist, isn't in us-east-1 region, isn't valid, or doesn't include a valid certificate chain.
if isAWSErr(err, cloudfront.ErrCodeInvalidViewerCertificate, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
return fmt.Errorf("error updating CloudFront Distribution (%s): %s", d.Id(), err)
}

if err := setTagsCloudFront(conn, d, d.Get("arn").(string)); err != nil {
Expand Down