Skip to content

Commit

Permalink
Merge pull request #7809 from terraform-providers/b-aws_cloudfront_di…
Browse files Browse the repository at this point in the history
…stribution-resourcetimeout-retry

resource/aws_cloudfront_distribution: Allow final creation and update timeout retry for AWS Go SDK retries
  • Loading branch information
bflad authored Mar 5, 2019
2 parents 1a4caf4 + 26abd93 commit 0b5b4e6
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,25 @@ func resourceAwsCloudFrontDistributionCreate(d *schema.ResourceData, meta interf
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.CreateDistributionWithTags(params)

// 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)
}

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
})

// Propagate AWS Go SDK retried error, if any
if isResourceTimeoutError(err) {
resp, err = conn.CreateDistributionWithTags(params)
}

if err != nil {
return fmt.Errorf("error creating CloudFront Distribution: %s", err)
}
Expand Down Expand Up @@ -785,16 +794,25 @@ func resourceAwsCloudFrontDistributionUpdate(d *schema.ResourceData, meta interf
// Handle eventual consistency issues
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateDistribution(params)

// 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)
}

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
})

// Propagate AWS Go SDK retried error, if any
if isResourceTimeoutError(err) {
_, err = conn.UpdateDistribution(params)
}

if err != nil {
return fmt.Errorf("error updating CloudFront Distribution (%s): %s", d.Id(), err)
}
Expand Down

0 comments on commit 0b5b4e6

Please sign in to comment.