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: required argument for aws_s3_bucket_lifecycle_configuration incorrectly set as optional #40796

Merged
7 changes: 7 additions & 0 deletions .changelog/40796.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:breaking-change
resource/aws_s3_bucket_lifecycle_configuration: `rule.noncurrent_version_expiration.noncurrent_days` and `rule.noncurrent_version_transition.noncurrent_days` are Required
```

```release-note:enhancement
resource/aws_s3_bucket_lifecycle_configuration: `rule.noncurrent_version_expiration.noncurrent_days` and `rule.noncurrent_version_transition.noncurrent_days` are Required. Technically this is a breaking change, but failure to configure this attribute would have led to `InvalidArgument` or `MalformedXML` errors
```
6 changes: 2 additions & 4 deletions internal/service/s3/bucket_lifecycle_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ func (r *resourceBucketLifecycleConfiguration) Schema(ctx context.Context, reque
},
},
"noncurrent_days": schema.Int32Attribute{
Optional: true,
Computed: true, // Because of schema change
Required: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknown(),
},
Expand All @@ -305,8 +304,7 @@ func (r *resourceBucketLifecycleConfiguration) Schema(ctx context.Context, reque
},
},
"noncurrent_days": schema.Int32Attribute{
Optional: true,
Computed: true, // Because of schema change
Required: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknown(),
},
Expand Down
43 changes: 38 additions & 5 deletions internal/service/s3/bucket_lifecycle_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,8 @@ func TestAccS3BucketLifecycleConfiguration_migrate_withChange(t *testing.T) {
})
}

// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/23884
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/23884.
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/38551.
func TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefix(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand All @@ -1600,7 +1601,7 @@ func TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefi
CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccBucketLifecycleConfigurationConfig_filterObjectSizeGreaterThanAndPrefix(rName, "prefix1"),
Config: testAccBucketLifecycleConfigurationConfig_filterObjectSizeGreaterThanAndPrefix(rName, "prefix1", 300),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName),
),
Expand Down Expand Up @@ -1631,6 +1632,38 @@ func TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefi
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("transition_default_minimum_object_size"), knownvalue.StringExact("all_storage_classes_128K")),
},
},
{
Config: testAccBucketLifecycleConfigurationConfig_filterObjectSizeGreaterThanAndPrefix(rName, "prefix1", 0),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrBucket), "aws_s3_bucket.test", tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrExpectedBucketOwner), knownvalue.StringExact("")),
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrID), resourceName, tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrRule), knownvalue.ListExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"abort_incomplete_multipart_upload": checkAbortIncompleteMultipartUpload_None(),
"expiration": checkExpiration_Days(90),
names.AttrFilter: checkFilter_And(
knownvalue.ObjectExact(map[string]knownvalue.Check{
"object_size_greater_than": knownvalue.Int64Exact(0),
"object_size_less_than": knownvalue.Int64Exact(0),
names.AttrPrefix: knownvalue.StringExact("prefix1"),
names.AttrTags: knownvalue.Null(),
}),
),
names.AttrID: knownvalue.StringExact(rName),
"noncurrent_version_expiration": checkNoncurrentVersionExpiration_None(),
"noncurrent_version_transition": checkNoncurrentVersionTransitions(),
names.AttrPrefix: knownvalue.StringExact(""),
names.AttrStatus: knownvalue.StringExact(tfs3.LifecycleRuleStatusEnabled),
"transition": checkTransitions(),
}),
})),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("transition_default_minimum_object_size"), knownvalue.StringExact("all_storage_classes_128K")),
},
},
{
Config: testAccBucketLifecycleConfigurationConfig_filterPrefix(rName, "prefix2"),
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -2771,7 +2804,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "test" {
`, rName, date, sizeGreaterThan, sizeLessThan)
}

func testAccBucketLifecycleConfigurationConfig_filterObjectSizeGreaterThanAndPrefix(rName, prefix string) string {
func testAccBucketLifecycleConfigurationConfig_filterObjectSizeGreaterThanAndPrefix(rName, prefix string, objectSizeGT int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "test" {
bucket = %[1]q
Expand All @@ -2789,14 +2822,14 @@ resource "aws_s3_bucket_lifecycle_configuration" "test" {

filter {
and {
object_size_greater_than = 300
object_size_greater_than = %[3]d
prefix = %[2]q
}
}

status = "Enabled"
}
}`, rName, prefix)
}`, rName, prefix, objectSizeGT)
}

func testAccBucketLifecycleConfigurationConfig_filterPrefix(rName, prefix string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ The `filter` configuration block supports the following arguments:
The `noncurrent_version_expiration` configuration block supports the following arguments:

* `newer_noncurrent_versions` - (Optional) Number of noncurrent versions Amazon S3 will retain. Must be a non-zero positive integer.
* `noncurrent_days` - (Optional) Number of days an object is noncurrent before Amazon S3 can perform the associated action. Must be a positive integer.
* `noncurrent_days` - (Required) Number of days an object is noncurrent before Amazon S3 can perform the associated action. Must be a positive integer.

### noncurrent_version_transition

The `noncurrent_version_transition` configuration block supports the following arguments:

* `newer_noncurrent_versions` - (Optional) Number of noncurrent versions Amazon S3 will retain. Must be a non-zero positive integer.
* `noncurrent_days` - (Optional) Number of days an object is noncurrent before Amazon S3 can perform the associated action.
* `noncurrent_days` - (Required) Number of days an object is noncurrent before Amazon S3 can perform the associated action.
* `storage_class` - (Required) Class of storage used to store the object. Valid Values: `GLACIER`, `STANDARD_IA`, `ONEZONE_IA`, `INTELLIGENT_TIERING`, `DEEP_ARCHIVE`, `GLACIER_IR`.

### transition
Expand Down
Loading