From 95359b4d1b0c6695b73bd61f31d69bf40a285892 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 23 Oct 2017 12:40:47 +0100 Subject: [PATCH] r/s3_bucket: Retry tagging on OperationAborted --- aws/awserr.go | 21 +++++++++++++++++++++ aws/s3_tags.go | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/aws/awserr.go b/aws/awserr.go index b0ca7400943..fb12edd6a0a 100644 --- a/aws/awserr.go +++ b/aws/awserr.go @@ -31,3 +31,24 @@ func retryOnAwsCode(code string, f func() (interface{}, error)) (interface{}, er }) return resp, err } + +func retryOnAwsCodes(codes []string, f func() (interface{}, error)) (interface{}, error) { + var resp interface{} + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + var err error + resp, err = f() + if err != nil { + awsErr, ok := err.(awserr.Error) + if ok { + for _, code := range codes { + if awsErr.Code() == code { + return resource.RetryableError(err) + } + } + } + return resource.NonRetryableError(err) + } + return nil + }) + return resp, err +} diff --git a/aws/s3_tags.go b/aws/s3_tags.go index e7f7c8248b7..8de14fa3f56 100644 --- a/aws/s3_tags.go +++ b/aws/s3_tags.go @@ -22,7 +22,7 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error { // Set tags if len(remove) > 0 { log.Printf("[DEBUG] Removing tags: %#v", remove) - _, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) { + _, err := retryOnAwsCodes([]string{"NoSuchBucket", "OperationAborted"}, func() (interface{}, error) { return conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{ Bucket: aws.String(d.Get("bucket").(string)), }) @@ -40,7 +40,7 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error { }, } - _, err := retryOnAwsCode("NoSuchBucket", func() (interface{}, error) { + _, err := retryOnAwsCodes([]string{"NoSuchBucket", "OperationAborted"}, func() (interface{}, error) { return conn.PutBucketTagging(req) }) if err != nil {