Skip to content

Commit

Permalink
Merge pull request #10863 from terraform-providers/b-aws_s3_bucket-re…
Browse files Browse the repository at this point in the history
…try-GetBucketTagging

resource/aws_s3_bucket: Retry GetBucketTagging API calls on NoSuchBucket errors due to eventual consistency
  • Loading branch information
gdavison authored Nov 14, 2019
2 parents aff4427 + d2b21b9 commit 476cf77
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions aws/s3_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,32 @@ import (
// s3.GetBucketTagging, except returns an empty slice instead of an error when
// there are no tags.
func getTagSetS3Bucket(conn *s3.S3, bucket string) ([]*s3.Tag, error) {
resp, err := conn.GetBucketTagging(&s3.GetBucketTaggingInput{
input := &s3.GetBucketTaggingInput{
Bucket: aws.String(bucket),
}

// Retry due to S3 eventual consistency
outputRaw, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) {
return conn.GetBucketTagging(input)
})

// S3 API Reference (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketTagging.html)
// lists the special error as NoSuchTagSetError, however the existing logic used NoSuchTagSet
// and the AWS Go SDK has neither as a constant.
if isAWSErr(err, "NoSuchTagSet", "") {
return nil, nil
}

if err != nil {
if isAWSErr(err, "NoSuchTagSet", "") {
return nil, nil
}
return nil, err
}

return resp.TagSet, nil
var tagSet []*s3.Tag
if output, ok := outputRaw.(*s3.GetBucketTaggingOutput); ok {
tagSet = output.TagSet
}

return tagSet, nil
}

// setTags is a helper to set the tags for a resource. It expects the
Expand Down

0 comments on commit 476cf77

Please sign in to comment.