From dc2da950cb6b86e5974b84ba046c376c5a8138ce Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Sun, 28 Jan 2024 00:21:08 -0500 Subject: [PATCH 1/2] fix: Set max # of lifecycle_policy blocks to 3 to allow setting all policies --- .changelog/35522.txt | 3 ++ internal/service/efs/file_system.go | 2 +- internal/service/efs/file_system_test.go | 43 ++++++++++++++++++++ website/docs/r/efs_file_system.html.markdown | 20 +++++---- 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 .changelog/35522.txt diff --git a/.changelog/35522.txt b/.changelog/35522.txt new file mode 100644 index 00000000000..a3bfbba3d34 --- /dev/null +++ b/.changelog/35522.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_efs_file_system: Fix max # of `lifecycle_policy` configuration blocks to allow setting all 3 policies +``` diff --git a/internal/service/efs/file_system.go b/internal/service/efs/file_system.go index 41d216f3c5e..e80f1b86289 100644 --- a/internal/service/efs/file_system.go +++ b/internal/service/efs/file_system.go @@ -85,7 +85,7 @@ func ResourceFileSystem() *schema.Resource { "lifecycle_policy": { Type: schema.TypeList, Optional: true, - MaxItems: 2, + MaxItems: 3, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "transition_to_archive": { diff --git a/internal/service/efs/file_system_test.go b/internal/service/efs/file_system_test.go index 2f65f69183a..98a29d40d84 100644 --- a/internal/service/efs/file_system_test.go +++ b/internal/service/efs/file_system_test.go @@ -436,6 +436,29 @@ func TestAccEFSFileSystem_lifecyclePolicy(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_primary_storage_class", ""), ), }, + { + Config: testAccFileSystemConfig_lifecyclePolicyAll( + "transition_to_primary_storage_class", + efs.TransitionToPrimaryStorageClassRulesAfter1Access, + "transition_to_ia", + efs.TransitionToIARulesAfter30Days, + "transition_to_archive", + efs.TransitionToArchiveRulesAfter60Days, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckFileSystem(ctx, resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "3"), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_archive", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_ia", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_primary_storage_class", efs.TransitionToPrimaryStorageClassRulesAfter1Access), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_archive", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_ia", efs.TransitionToIARulesAfter30Days), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_primary_storage_class", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.2.transition_to_archive", efs.TransitionToArchiveRulesAfter60Days), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.2.transition_to_ia", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.2.transition_to_primary_storage_class", ""), + ), + }, { Config: testAccFileSystemConfig_lifecyclePolicyTransitionToArchive( "transition_to_ia", @@ -694,6 +717,26 @@ resource "aws_efs_file_system" "test" { `, lpName1, lpVal1, lpName2, lpVal2) } +func testAccFileSystemConfig_lifecyclePolicyAll(lpName1, lpVal1, lpName2, lpVal2, lpName3, lpVal3 string) string { + return fmt.Sprintf(` +resource "aws_efs_file_system" "test" { + throughput_mode = "elastic" + + lifecycle_policy { + %[1]s = %[2]q + } + + lifecycle_policy { + %[3]s = %[4]q + } + + lifecycle_policy { + %[5]s = %[6]q + } +} +`, lpName1, lpVal1, lpName2, lpVal2, lpName3, lpVal3) +} + func testAccFileSystemConfig_lifecyclePolicyTransitionToArchive(lpName1, lpVal1, lpName2, lpVal2 string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { diff --git a/website/docs/r/efs_file_system.html.markdown b/website/docs/r/efs_file_system.html.markdown index 6b8dfea9c0c..094bb6fd9c2 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -47,24 +47,28 @@ system creation. By default generated by Terraform. See [Elastic File System](ht user guide for more information. * `encrypted` - (Optional) If true, the disk will be encrypted. * `kms_key_id` - (Optional) The ARN for the KMS encryption key. When specifying kms_key_id, encrypted needs to be set to true. -* `lifecycle_policy` - (Optional) A file system [lifecycle policy](https://docs.aws.amazon.com/efs/latest/ug/API_LifecyclePolicy.html) object (documented below). -* `protection` - (Optional) A file system [protection](https://docs.aws.amazon.com/efs/latest/ug/API_FileSystemProtectionDescription.html) object (documented below). +* `lifecycle_policy` - (Optional) A file system [lifecycle policy](https://docs.aws.amazon.com/efs/latest/ug/API_LifecyclePolicy.html) object. See [`lifecycle_policy` block](#lifecycle_policy-block) below for details. +* `protection` - (Optional) A file system [protection](https://docs.aws.amazon.com/efs/latest/ug/API_FileSystemProtectionDescription.html) object. See [`protection` block](#protection-block) below for details. * `performance_mode` - (Optional) The file system performance mode. Can be either `"generalPurpose"` or `"maxIO"` (Default: `"generalPurpose"`). * `provisioned_throughput_in_mibps` - (Optional) The throughput, measured in MiB/s, that you want to provision for the file system. Only applicable with `throughput_mode` set to `provisioned`. * `tags` - (Optional) A map of tags to assign to the file system. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `throughput_mode` - (Optional) Throughput mode for the file system. Defaults to `bursting`. Valid values: `bursting`, `provisioned`, or `elastic`. When using `provisioned`, also set `provisioned_throughput_in_mibps`. -### Lifecycle Policy Arguments +### `lifecycle_policy` Block -`lifecycle_policy` supports the following arguments: +Describes a policy used by Lifecycle management that specifies when to transition files into and out of storage classes. For more information, see [Managing file system storage](https://docs.aws.amazon.com/efs/latest/ug/lifecycle-management-efs.html). -* `transition_to_ia` - (Optional) Indicates how long it takes to transition files to the IA storage class. Valid values: `AFTER_1_DAY`, `AFTER_7_DAYS`, `AFTER_14_DAYS`, `AFTER_30_DAYS`, `AFTER_60_DAYS`, or `AFTER_90_DAYS`. +The `lifecycle_policy` block supports the following arguments: + +* `transition_to_archive` - (Optional) Indicates how long it takes to transition files to the archive storage class. Requires transition_to_ia, Elastic Throughput and General Purpose performance mode. Valid values: `AFTER_1_DAY`, `AFTER_7_DAYS`, `AFTER_14_DAYS`, `AFTER_30_DAYS`, `AFTER_60_DAYS`, `AFTER_90_DAYS`, `AFTER_180_DAYS`, `AFTER_270_DAYS`, or `AFTER_365_DAYS`. +* `transition_to_ia` - (Optional) Indicates how long it takes to transition files to the IA storage class. Valid values: `AFTER_1_DAY`, `AFTER_7_DAYS`, `AFTER_14_DAYS`, `AFTER_30_DAYS`, `AFTER_60_DAYS`, `AFTER_90_DAYS`, `AFTER_180_DAYS`, `AFTER_270_DAYS`, or `AFTER_365_DAYS`. * `transition_to_primary_storage_class` - (Optional) Describes the policy used to transition a file from infequent access storage to primary storage. Valid values: `AFTER_1_ACCESS`. -* `transition_to_archive` - (Optional) Indicates how long it takes to transition files to the archive storage class. Requires transition_to_ia, Elastic Throughput and General Purpose performance mode. Valid values: `AFTER_1_DAY`, `AFTER_7_DAYS`, `AFTER_14_DAYS`, `AFTER_30_DAYS`, `AFTER_60_DAYS`, or `AFTER_90_DAYS`. -### Protection Arguments +### `protection` Block + +Describes the protection on a file system. -`protection` supports the following arguments: +The `protection` block supports the following arguments: * `replication_overwrite` - (Optional) Indicates whether replication overwrite protection is enabled. Valid values: `ENABLED` or `DISABLED`. From a260128a284a87e259ce3d2f1b2496e1d7911a00 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 29 Jan 2024 09:03:14 -0500 Subject: [PATCH 2/2] Tweak CHANGELOG entry. --- .changelog/35522.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/35522.txt b/.changelog/35522.txt index a3bfbba3d34..84c2d6920c5 100644 --- a/.changelog/35522.txt +++ b/.changelog/35522.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_efs_file_system: Fix max # of `lifecycle_policy` configuration blocks to allow setting all 3 policies +resource/aws_efs_file_system: Increase `lifecycle_policy` maximum item limit to 3 ```