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

Fix intermittent error putting S3 lifecycle: NoSuchBucket #7930

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion aws/awserr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func isAWSErr(err error, code string, message string) bool {

func retryOnAwsCode(code string, f func() (interface{}, error)) (interface{}, error) {
var resp interface{}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
var err error
resp, err = f()
if err != nil {
Expand Down
57 changes: 27 additions & 30 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

var err error

_, err = retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err = retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.HeadBucket(&s3.HeadBucketInput{
Bucket: aws.String(d.Id()),
})
Expand All @@ -781,7 +781,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
// Read the policy
if _, ok := d.GetOk("policy"); ok {

pol, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
pol, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketPolicy(&s3.GetBucketPolicyInput{
Bucket: aws.String(d.Id()),
})
Expand All @@ -807,7 +807,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
}

// Read the CORS
corsResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
corsResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketCors(&s3.GetBucketCorsInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -839,7 +839,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
}

// Read the website configuration
wsResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
wsResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketWebsite(&s3.GetBucketWebsiteInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -906,7 +906,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the versioning configuration

versioningResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
versioningResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketVersioning(&s3.GetBucketVersioningInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -937,7 +937,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the acceleration status

accelerateResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
accelerateResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketAccelerateConfiguration(&s3.GetBucketAccelerateConfigurationInput{
Bucket: aws.String(d.Id()),
})
Expand All @@ -953,7 +953,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the request payer configuration.

payerResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
payerResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketRequestPayment(&s3.GetBucketRequestPaymentInput{
Bucket: aws.String(d.Id()),
})
Expand All @@ -968,7 +968,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
}

// Read the logging configuration
loggingResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
loggingResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketLogging(&s3.GetBucketLoggingInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -996,7 +996,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the lifecycle configuration

lifecycleResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
lifecycleResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketLifecycleConfiguration(&s3.GetBucketLifecycleConfigurationInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -1120,7 +1120,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the bucket replication configuration

replicationResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
replicationResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketReplication(&s3.GetBucketReplicationInput{
Bucket: aws.String(d.Id()),
})
Expand All @@ -1139,7 +1139,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Read the bucket server side encryption configuration

encryptionResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
encryptionResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketEncryption(&s3.GetBucketEncryptionInput{
Bucket: aws.String(d.Id()),
})
Expand Down Expand Up @@ -1167,7 +1167,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {

// Add the region as an attribute

locationResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
locationResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketLocation(
&s3.GetBucketLocationInput{
Bucket: aws.String(d.Id()),
Expand Down Expand Up @@ -1324,7 +1324,7 @@ func resourceAwsS3BucketPolicyUpdate(s3conn *s3.S3, d *schema.ResourceData) erro
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
if _, err := s3conn.PutBucketPolicy(params); err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "MalformedPolicy" || awserr.Code() == "NoSuchBucket" {
if awserr.Code() == "MalformedPolicy" || awserr.Code() == s3.ErrCodeNoSuchBucket {
return resource.RetryableError(awserr)
}
}
Expand All @@ -1338,7 +1338,7 @@ func resourceAwsS3BucketPolicyUpdate(s3conn *s3.S3, d *schema.ResourceData) erro
}
} else {
log.Printf("[DEBUG] S3 bucket: %s, delete policy: %s", bucket, policy)
_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.DeleteBucketPolicy(&s3.DeleteBucketPolicyInput{
Bucket: aws.String(bucket),
})
Expand All @@ -1360,7 +1360,7 @@ func resourceAwsS3BucketCorsUpdate(s3conn *s3.S3, d *schema.ResourceData) error
// Delete CORS
log.Printf("[DEBUG] S3 bucket: %s, delete CORS", bucket)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.DeleteBucketCors(&s3.DeleteBucketCorsInput{
Bucket: aws.String(bucket),
})
Expand Down Expand Up @@ -1407,7 +1407,7 @@ func resourceAwsS3BucketCorsUpdate(s3conn *s3.S3, d *schema.ResourceData) error
}
log.Printf("[DEBUG] S3 bucket: %s, put CORS: %#v", bucket, corsInput)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketCors(corsInput)
})
if err != nil {
Expand Down Expand Up @@ -1498,7 +1498,7 @@ func resourceAwsS3BucketWebsitePut(s3conn *s3.S3, d *schema.ResourceData, websit

log.Printf("[DEBUG] S3 put bucket website: %#v", putInput)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketWebsite(putInput)
})
if err != nil {
Expand All @@ -1514,7 +1514,7 @@ func resourceAwsS3BucketWebsiteDelete(s3conn *s3.S3, d *schema.ResourceData) err

log.Printf("[DEBUG] S3 delete bucket website: %#v", deleteInput)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.DeleteBucketWebsite(deleteInput)
})
if err != nil {
Expand All @@ -1538,7 +1538,7 @@ func websiteEndpoint(s3conn *s3.S3, d *schema.ResourceData) (*S3Website, error)

// Lookup the region for this bucket

locationResponse, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
locationResponse, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.GetBucketLocation(
&s3.GetBucketLocationInput{
Bucket: aws.String(bucket),
Expand Down Expand Up @@ -1621,7 +1621,7 @@ func resourceAwsS3BucketAclUpdate(s3conn *s3.S3, d *schema.ResourceData) error {
}
log.Printf("[DEBUG] S3 put bucket ACL: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketAcl(i)
})
if err != nil {
Expand Down Expand Up @@ -1661,7 +1661,7 @@ func resourceAwsS3BucketVersioningUpdate(s3conn *s3.S3, d *schema.ResourceData)
}
log.Printf("[DEBUG] S3 put bucket versioning: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketVersioning(i)
})
if err != nil {
Expand Down Expand Up @@ -1696,7 +1696,7 @@ func resourceAwsS3BucketLoggingUpdate(s3conn *s3.S3, d *schema.ResourceData) err
}
log.Printf("[DEBUG] S3 put bucket logging: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketLogging(i)
})
if err != nil {
Expand All @@ -1718,7 +1718,7 @@ func resourceAwsS3BucketAccelerationUpdate(s3conn *s3.S3, d *schema.ResourceData
}
log.Printf("[DEBUG] S3 put bucket acceleration: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketAccelerateConfiguration(i)
})
if err != nil {
Expand All @@ -1740,7 +1740,7 @@ func resourceAwsS3BucketRequestPayerUpdate(s3conn *s3.S3, d *schema.ResourceData
}
log.Printf("[DEBUG] S3 put bucket request payer: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketRequestPayment(i)
})
if err != nil {
Expand Down Expand Up @@ -1802,7 +1802,7 @@ func resourceAwsS3BucketServerSideEncryptionConfigurationUpdate(s3conn *s3.S3, d
}
log.Printf("[DEBUG] S3 put bucket replication configuration: %#v", i)

_, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) {
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketEncryption(i)
})
if err != nil {
Expand Down Expand Up @@ -2126,11 +2126,8 @@ func resourceAwsS3BucketLifecycleUpdate(s3conn *s3.S3, d *schema.ResourceData) e
},
}

err := resource.Retry(1*time.Minute, func() *resource.RetryError {
if _, err := s3conn.PutBucketLifecycleConfiguration(i); err != nil {
return resource.NonRetryableError(err)
}
return nil
_, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return s3conn.PutBucketLifecycleConfiguration(i)
})
if err != nil {
return fmt.Errorf("Error putting S3 lifecycle: %s", err)
Expand Down