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

resource/s3_bucket: check for additional rule action before adding default expiration setting #15263

Merged
merged 1 commit into from
Oct 8, 2020
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
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 @@ -1341,6 +1341,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 @@ -3640,6 +3666,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