diff --git a/.changelog/40268.txt b/.changelog/40268.txt new file mode 100644 index 00000000000..a32f43f014f --- /dev/null +++ b/.changelog/40268.txt @@ -0,0 +1,3 @@ +```release-note:note +resource/aws_s3_bucket_lifecycle_configuration: Lifecycle configurations can now be applied to directory buckets +``` diff --git a/internal/service/s3/bucket_lifecycle_configuration_test.go b/internal/service/s3/bucket_lifecycle_configuration_test.go index e6aac6b1cfc..1064fe4ca50 100644 --- a/internal/service/s3/bucket_lifecycle_configuration_test.go +++ b/internal/service/s3/bucket_lifecycle_configuration_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/service/s3/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -1053,6 +1052,7 @@ func TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefi func TestAccS3BucketLifecycleConfiguration_directoryBucket(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_s3_bucket_lifecycle_configuration.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -1061,8 +1061,20 @@ func TestAccS3BucketLifecycleConfiguration_directoryBucket(t *testing.T) { CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccBucketLifecycleConfigurationConfig_directoryBucket(rName), - ExpectError: regexache.MustCompile(`MethodNotAllowed: The specified method is not allowed against this resource`), + Config: testAccBucketLifecycleConfigurationConfig_directoryBucket(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, names.AttrBucket, "aws_s3_directory_bucket.test", names.AttrBucket), + resource.TestCheckResourceAttr(resourceName, acctest.CtRulePound, "1"), + resource.TestCheckResourceAttr(resourceName, "rule.0.status", "Enabled"), + resource.TestCheckResourceAttr(resourceName, "rule.0.expiration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "rule.0.expiration.0.days", "365"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) diff --git a/website/docs/r/s3_bucket_lifecycle_configuration.html.markdown b/website/docs/r/s3_bucket_lifecycle_configuration.html.markdown index 16c0ad7de9f..f7c434ba7f9 100644 --- a/website/docs/r/s3_bucket_lifecycle_configuration.html.markdown +++ b/website/docs/r/s3_bucket_lifecycle_configuration.html.markdown @@ -18,14 +18,12 @@ An S3 Lifecycle configuration consists of one or more Lifecycle rules. Each rule For more information see the Amazon S3 User Guide on [`Lifecycle Configuration Elements`](https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html). -~> **NOTE:** S3 Buckets only support a single lifecycle configuration. Declaring multiple `aws_s3_bucket_lifecycle_configuration` resources to the same S3 Bucket will cause a perpetual difference in configuration. +~> S3 Buckets only support a single lifecycle configuration. Declaring multiple `aws_s3_bucket_lifecycle_configuration` resources to the same S3 Bucket will cause a perpetual difference in configuration. -~> **NOTE:** Lifecycle configurations may take some time to fully propagate to all AWS S3 systems. +~> Lifecycle configurations may take some time to fully propagate to all AWS S3 systems. Running Terraform operations shortly after creating a lifecycle configuration may result in changes that affect configuration idempotence. See the Amazon S3 User Guide on [setting lifecycle configuration on a bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html). --> This resource cannot be used with S3 directory buckets. - ## Example Usage ### With neither a filter nor prefix specified @@ -374,12 +372,12 @@ This resource supports the following arguments: ### rule -~> **NOTE:** The `filter` argument, while Optional, is required if the `rule` configuration block does not contain a `prefix` **and** you intend to override the default behavior of setting the rule to filter objects with the empty string prefix (`""`). +~> The `filter` argument, while Optional, is required if the `rule` configuration block does not contain a `prefix` **and** you intend to override the default behavior of setting the rule to filter objects with the empty string prefix (`""`). Since `prefix` is deprecated by Amazon S3 and will be removed in the next major version of the Terraform AWS Provider, we recommend users either specify `filter` or leave both `filter` and `prefix` unspecified. -~> **NOTE:** A rule cannot be updated from having a filter (via either the `rule.filter` parameter or when neither `rule.filter` and `rule.prefix` are specified) to only having a prefix via the `rule.prefix` parameter. +~> A rule cannot be updated from having a filter (via either the `rule.filter` parameter or when neither `rule.filter` and `rule.prefix` are specified) to only having a prefix via the `rule.prefix` parameter. -~> **NOTE** Terraform cannot distinguish a difference between configurations that use `rule.filter {}` and configurations that neither use `rule.filter` nor `rule.prefix`, so a rule cannot be updated from applying to all objects in the bucket via `rule.filter {}` to applying to a subset of objects based on the key prefix `""` and vice versa. +~> Terraform cannot distinguish a difference between configurations that use `rule.filter {}` and configurations that neither use `rule.filter` nor `rule.prefix`, so a rule cannot be updated from applying to all objects in the bucket via `rule.filter {}` to applying to a subset of objects based on the key prefix `""` and vice versa. The `rule` configuration block supports the following arguments: @@ -409,7 +407,7 @@ The `expiration` configuration block supports the following arguments: ### filter -~> **NOTE:** The `filter` configuration block must either be specified as the empty configuration block (`filter {}`) or with exactly one of `prefix`, `tag`, `and`, `object_size_greater_than` or `object_size_less_than` specified. +~> The `filter` configuration block must either be specified as the empty configuration block (`filter {}`) or with exactly one of `prefix`, `tag`, `and`, `object_size_greater_than` or `object_size_less_than` specified. The `filter` configuration block supports the following arguments: @@ -438,7 +436,7 @@ The `noncurrent_version_transition` configuration block supports the following a The `transition` configuration block supports the following arguments: -~> **Note:** Only one of `date` or `days` should be specified. If neither are specified, the `transition` will default to 0 `days`. +~> Only one of `date` or `days` should be specified. If neither are specified, the `transition` will default to 0 `days`. * `date` - (Optional, Conflicts with `days`) Date objects are transitioned to the specified storage class. The date value must be in [RFC3339 full-date format](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) e.g. `2023-08-22`. * `days` - (Optional, Conflicts with `date`) Number of days after creation when objects are transitioned to the specified storage class. The value must be a positive integer. If both `days` and `date` are not specified, defaults to `0`. Valid values depend on `storage_class`, see [Transition objects using Amazon S3 Lifecycle](https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-transition-general-considerations.html) for more details. @@ -468,7 +466,7 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import S3 bucket lifecycle configuration using the `bucket` or using the `bucket` and `expected_bucket_owner` separated by a comma (`,`). For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import an S3 bucket lifecycle configuration using the `bucket` or the `bucket` and `expected_bucket_owner` separated by a comma (`,`). For example: If the owner (account ID) of the source bucket is the same account used to configure the Terraform AWS Provider, import using the `bucket`: @@ -488,7 +486,7 @@ import { } ``` -**Using `terraform import` to import** S3 bucket lifecycle configuration using the `bucket` or using the `bucket` and `expected_bucket_owner` separated by a comma (`,`). For example: +Using `terraform import`, import an S3 bucket lifecycle configuration using the `bucket` or the `bucket` and `expected_bucket_owner` separated by a comma (`,`). For example: If the owner (account ID) of the source bucket is the same account used to configure the Terraform AWS Provider, import using the `bucket`: