@@ -1665,6 +1665,112 @@ func TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration(t *testin
1665
1665
})
1666
1666
}
1667
1667
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
+
1668
1774
func TestAccS3BucketLifecycleConfiguration_nonCurrentVersionTransition (t * testing.T ) {
1669
1775
ctx := acctest .Context (t )
1670
1776
rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
@@ -4593,6 +4699,59 @@ resource "aws_s3_bucket_lifecycle_configuration" "test" {
4593
4699
` , rName , nonCurrentDays )
4594
4700
}
4595
4701
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
+
4596
4755
func testAccBucketLifecycleConfigurationConfig_nonCurrentVersionTransition (rName string , standardDays , glacierDays int ) string {
4597
4756
return fmt .Sprintf (`
4598
4757
resource "aws_s3_bucket" "test" {
0 commit comments