Skip to content

Commit 127c376

Browse files
committed
noncurrent_version_expiration.newer_noncurrent_versions and noncurrent_version_transition.newer_noncurrent_versions do not need to be Computed and have extra Plan Modifiers
1 parent e7e0864 commit 127c376

File tree

3 files changed

+159
-59
lines changed

3 files changed

+159
-59
lines changed

internal/framework/planmodifiers/int32planmodifier/null_value.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

internal/service/s3/bucket_lifecycle_configuration.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,6 @@ func (r *bucketLifecycleConfigurationResource) Schema(ctx context.Context, reque
298298
Attributes: map[string]schema.Attribute{
299299
"newer_noncurrent_versions": schema.Int32Attribute{
300300
Optional: true,
301-
Computed: true, // Because of schema change
302-
PlanModifiers: []planmodifier.Int32{
303-
tfint32planmodifier.NullValue(),
304-
int32planmodifier.UseStateForUnknown(),
305-
},
306301
Validators: []validator.Int32{
307302
int32validator.AtLeast(1),
308303
},
@@ -325,11 +320,6 @@ func (r *bucketLifecycleConfigurationResource) Schema(ctx context.Context, reque
325320
Attributes: map[string]schema.Attribute{
326321
"newer_noncurrent_versions": schema.Int32Attribute{
327322
Optional: true,
328-
Computed: true, // Because of schema change
329-
PlanModifiers: []planmodifier.Int32{
330-
tfint32planmodifier.NullValue(),
331-
int32planmodifier.UseStateForUnknown(),
332-
},
333323
Validators: []validator.Int32{
334324
int32validator.AtLeast(1),
335325
},

internal/service/s3/bucket_lifecycle_configuration_test.go

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,112 @@ func TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration(t *testin
16651665
})
16661666
}
16671667

1668+
func TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration_RemoveNoncurrentVersions(t *testing.T) {
1669+
ctx := acctest.Context(t)
1670+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1671+
resourceName := "aws_s3_bucket_lifecycle_configuration.test"
1672+
1673+
resource.ParallelTest(t, resource.TestCase{
1674+
PreCheck: func() { acctest.PreCheck(ctx, t) },
1675+
ErrorCheck: acctest.ErrorCheck(t, names.S3ServiceID),
1676+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
1677+
CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx),
1678+
Steps: []resource.TestStep{
1679+
{
1680+
Config: testAccBucketLifecycleConfigurationConfig_nonCurrentVersionExpiration_RemoveNoncurrentVersions_Setup(rName, 5, 90),
1681+
Check: resource.ComposeAggregateTestCheckFunc(
1682+
testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName),
1683+
),
1684+
ConfigStateChecks: []statecheck.StateCheck{
1685+
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrBucket), "aws_s3_bucket.test", tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
1686+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrExpectedBucketOwner), knownvalue.StringExact("")),
1687+
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrID), resourceName, tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
1688+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrRule), knownvalue.ListExact([]knownvalue.Check{
1689+
knownvalue.ObjectExact(map[string]knownvalue.Check{
1690+
"abort_incomplete_multipart_upload": checkAbortIncompleteMultipartUpload_None(),
1691+
"expiration": checkExpiration_None(),
1692+
names.AttrFilter: checkFilter_Prefix("config/"),
1693+
names.AttrID: knownvalue.StringExact(rName),
1694+
"noncurrent_version_expiration": checkNoncurrentVersionExpiration_VersionsAndDays(5, 90),
1695+
"noncurrent_version_transition": checkNoncurrentVersionTransitions(),
1696+
names.AttrPrefix: knownvalue.StringExact(""),
1697+
names.AttrStatus: knownvalue.StringExact(tfs3.LifecycleRuleStatusEnabled),
1698+
"transition": checkTransitions(),
1699+
}),
1700+
})),
1701+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("transition_default_minimum_object_size"), knownvalue.StringExact("all_storage_classes_128K")),
1702+
},
1703+
ConfigPlanChecks: resource.ConfigPlanChecks{
1704+
PreApply: []plancheck.PlanCheck{
1705+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
1706+
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrRule), knownvalue.ListExact([]knownvalue.Check{
1707+
knownvalue.ObjectExact(map[string]knownvalue.Check{
1708+
"abort_incomplete_multipart_upload": checkAbortIncompleteMultipartUpload_None(),
1709+
"expiration": checkExpiration_None(),
1710+
names.AttrFilter: checkFilter_Prefix("config/"),
1711+
names.AttrID: knownvalue.StringExact(rName),
1712+
"noncurrent_version_expiration": checkNoncurrentVersionExpiration_VersionsAndDays(5, 90),
1713+
"noncurrent_version_transition": checkNoncurrentVersionTransitions(),
1714+
names.AttrPrefix: knownvalue.StringExact(""),
1715+
names.AttrStatus: knownvalue.StringExact(tfs3.LifecycleRuleStatusEnabled),
1716+
"transition": checkTransitions(),
1717+
}),
1718+
})),
1719+
},
1720+
},
1721+
},
1722+
{
1723+
Config: testAccBucketLifecycleConfigurationConfig_nonCurrentVersionExpiration_RemoveNoncurrentVersions_Apply(rName, 90),
1724+
Check: resource.ComposeAggregateTestCheckFunc(
1725+
testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName),
1726+
),
1727+
ConfigStateChecks: []statecheck.StateCheck{
1728+
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrBucket), "aws_s3_bucket.test", tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
1729+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrExpectedBucketOwner), knownvalue.StringExact("")),
1730+
statecheck.CompareValuePairs(resourceName, tfjsonpath.New(names.AttrID), resourceName, tfjsonpath.New(names.AttrBucket), compare.ValuesSame()),
1731+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrRule), knownvalue.ListExact([]knownvalue.Check{
1732+
knownvalue.ObjectExact(map[string]knownvalue.Check{
1733+
"abort_incomplete_multipart_upload": checkAbortIncompleteMultipartUpload_None(),
1734+
"expiration": checkExpiration_None(),
1735+
names.AttrFilter: checkFilter_Prefix("config/"),
1736+
names.AttrID: knownvalue.StringExact(rName),
1737+
"noncurrent_version_expiration": checkNoncurrentVersionExpiration_Days(90),
1738+
"noncurrent_version_transition": checkNoncurrentVersionTransitions(),
1739+
names.AttrPrefix: knownvalue.StringExact(""),
1740+
names.AttrStatus: knownvalue.StringExact(tfs3.LifecycleRuleStatusEnabled),
1741+
"transition": checkTransitions(),
1742+
}),
1743+
})),
1744+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("transition_default_minimum_object_size"), knownvalue.StringExact("all_storage_classes_128K")),
1745+
},
1746+
ConfigPlanChecks: resource.ConfigPlanChecks{
1747+
PreApply: []plancheck.PlanCheck{
1748+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
1749+
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrRule), knownvalue.ListExact([]knownvalue.Check{
1750+
knownvalue.ObjectExact(map[string]knownvalue.Check{
1751+
"abort_incomplete_multipart_upload": checkAbortIncompleteMultipartUpload_None(),
1752+
"expiration": checkExpiration_None(),
1753+
names.AttrFilter: checkFilter_Prefix("config/"),
1754+
names.AttrID: knownvalue.StringExact(rName),
1755+
"noncurrent_version_expiration": checkNoncurrentVersionExpiration_Days(90),
1756+
"noncurrent_version_transition": checkNoncurrentVersionTransitions(),
1757+
names.AttrPrefix: knownvalue.StringExact(""),
1758+
names.AttrStatus: knownvalue.StringExact(tfs3.LifecycleRuleStatusEnabled),
1759+
"transition": checkTransitions(),
1760+
}),
1761+
})),
1762+
},
1763+
},
1764+
},
1765+
{
1766+
ResourceName: resourceName,
1767+
ImportState: true,
1768+
ImportStateVerify: true,
1769+
},
1770+
},
1771+
})
1772+
}
1773+
16681774
func TestAccS3BucketLifecycleConfiguration_nonCurrentVersionTransition(t *testing.T) {
16691775
ctx := acctest.Context(t)
16701776
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -4593,6 +4699,59 @@ resource "aws_s3_bucket_lifecycle_configuration" "test" {
45934699
`, rName, nonCurrentDays)
45944700
}
45954701

4702+
func testAccBucketLifecycleConfigurationConfig_nonCurrentVersionExpiration_RemoveNoncurrentVersions_Setup(rName string, nonCurrentVersions, nonCurrentDays int) string {
4703+
return fmt.Sprintf(`
4704+
resource "aws_s3_bucket" "test" {
4705+
bucket = %[1]q
4706+
}
4707+
4708+
resource "aws_s3_bucket_lifecycle_configuration" "test" {
4709+
bucket = aws_s3_bucket.test.bucket
4710+
4711+
rule {
4712+
id = %[1]q
4713+
4714+
filter {
4715+
prefix = "config/"
4716+
}
4717+
4718+
noncurrent_version_expiration {
4719+
newer_noncurrent_versions = %[2]d
4720+
noncurrent_days = %[3]d
4721+
}
4722+
4723+
status = "Enabled"
4724+
}
4725+
}
4726+
`, rName, nonCurrentVersions, nonCurrentDays)
4727+
}
4728+
4729+
func testAccBucketLifecycleConfigurationConfig_nonCurrentVersionExpiration_RemoveNoncurrentVersions_Apply(rName string, nonCurrentDays int) string {
4730+
return fmt.Sprintf(`
4731+
resource "aws_s3_bucket" "test" {
4732+
bucket = %[1]q
4733+
}
4734+
4735+
resource "aws_s3_bucket_lifecycle_configuration" "test" {
4736+
bucket = aws_s3_bucket.test.bucket
4737+
4738+
rule {
4739+
id = %[1]q
4740+
4741+
filter {
4742+
prefix = "config/"
4743+
}
4744+
4745+
noncurrent_version_expiration {
4746+
noncurrent_days = %[2]d
4747+
}
4748+
4749+
status = "Enabled"
4750+
}
4751+
}
4752+
`, rName, nonCurrentDays)
4753+
}
4754+
45964755
func testAccBucketLifecycleConfigurationConfig_nonCurrentVersionTransition(rName string, standardDays, glacierDays int) string {
45974756
return fmt.Sprintf(`
45984757
resource "aws_s3_bucket" "test" {

0 commit comments

Comments
 (0)