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 S3 bucket lifecycle rule filters with a single tag and no prefix #7162

Merged
merged 5 commits into from
Jul 10, 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
5 changes: 5 additions & 0 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
lifecycleRules = make([]map[string]interface{}, 0, len(lifecycle.Rules))

for _, lifecycleRule := range lifecycle.Rules {
log.Printf("[DEBUG] S3 bucket: %s, read lifecycle rule: %v", d.Id(), lifecycleRule)
rule := make(map[string]interface{})

// ID
Expand All @@ -1033,6 +1034,10 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
if filter.Prefix != nil && *filter.Prefix != "" {
rule["prefix"] = *filter.Prefix
}
// Tag
if filter.Tag != nil {
rule["tags"] = tagsToMapS3([]*s3.Tag{filter.Tag})
}
}
} else {
if lifecycleRule.Prefix != nil {
Expand Down
47 changes: 46 additions & 1 deletion aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func TestAccAWSS3Bucket_Logging(t *testing.T) {
})
}

func TestAccAWSS3Bucket_Lifecycle(t *testing.T) {
func TestAccAWSS3Bucket_LifecycleBasic(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: this allows to target this acceptance test without also matching the TestAccAWSS3Bucket_LifecycleExpireMarkerOnly test.

rInt := acctest.RandInt()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -942,6 +942,24 @@ func TestAccAWSS3Bucket_Lifecycle(t *testing.T) {
"aws_s3_bucket.bucket", "lifecycle_rule.3.tags.tagKey", "tagValue"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.3.tags.terraform", "hashicorp"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.4.id", "id5"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.4.tags.tagKey", "tagValue"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.4.tags.terraform", "hashicorp"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.4.transition.460947558.days", "0"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.4.transition.460947558.storage_class", "GLACIER"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.5.id", "id6"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.5.tags.tagKey", "tagValue"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.5.transition.460947558.days", "0"),
resource.TestCheckResourceAttr(
"aws_s3_bucket.bucket", "lifecycle_rule.5.transition.460947558.storage_class", "GLACIER"),
),
},
{
Expand Down Expand Up @@ -2539,6 +2557,33 @@ resource "aws_s3_bucket" "bucket" {
date = "2016-01-12"
}
}
lifecycle_rule {
id = "id5"
enabled = true

tags = {
"tagKey" = "tagValue"
"terraform" = "hashicorp"
}

transition {
days = 0
storage_class = "GLACIER"
}
}
lifecycle_rule {
id = "id6"
enabled = true

tags = {
"tagKey" = "tagValue"
}

transition {
days = 0
storage_class = "GLACIER"
}
}
}
`, randInt)
}
Expand Down