Skip to content

Commit

Permalink
Merge pull request #15263 from terraform-providers/b-s3-bucket-lifecy…
Browse files Browse the repository at this point in the history
…cle-expiration

resource/s3_bucket: check for additional rule action before adding default expiration setting
  • Loading branch information
gdavison authored Oct 8, 2020
2 parents 6e3df24 + a412c4e commit cb4033d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,8 @@ func resourceAwsS3BucketLifecycleUpdate(s3conn *s3.S3, d *schema.ResourceData) e
// we explicitly pass a default ExpiredObjectDeleteMarker value to be able to create
// the rule while keeping the policy unaffected if the conditions are not met.
if rule.Expiration == nil && rule.NoncurrentVersionExpiration == nil &&
rule.Transitions == nil && rule.NoncurrentVersionTransitions == nil {
rule.Transitions == nil && rule.NoncurrentVersionTransitions == nil &&
rule.AbortIncompleteMultipartUpload == nil {
rule.Expiration = &s3.LifecycleExpiration{ExpiredObjectDeleteMarker: aws.Bool(false)}
}

Expand Down
40 changes: 40 additions & 0 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,32 @@ func TestAccAWSS3Bucket_LifecycleRule_Expiration_EmptyConfigurationBlock(t *test
})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/15138
func TestAccAWSS3Bucket_LifecycleRule_AbortIncompleteMultipartUploadDays_NoExpiration(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_s3_bucket.bucket"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSS3BucketConfigLifecycleRuleAbortIncompleteMultipartUploadDays(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "acl"},
},
},
})
}

func TestAccAWSS3Bucket_Replication(t *testing.T) {
rInt := acctest.RandInt()
alternateRegion := testAccGetAlternateRegion()
Expand Down Expand Up @@ -3711,6 +3737,20 @@ resource "aws_s3_bucket" "bucket" {
`, rName)
}

func testAccAWSS3BucketConfigLifecycleRuleAbortIncompleteMultipartUploadDays(rName string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
bucket = %[1]q
lifecycle_rule {
abort_incomplete_multipart_upload_days = 7
enabled = true
id = "id1"
}
}
`, rName)
}

func testAccAWSS3BucketConfigReplicationBasic(randInt int) string {
return testAccAlternateRegionProviderConfig() + fmt.Sprintf(`
data "aws_partition" "current" {}
Expand Down

0 comments on commit cb4033d

Please sign in to comment.