diff --git a/.changelog/35096.txt b/.changelog/35096.txt new file mode 100644 index 00000000000..18e6652a08b --- /dev/null +++ b/.changelog/35096.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_efs_file_system: Add `lifecycle_policy.transition_to_archive` argument +``` + +```release-note:enhancement +data-source/aws_efs_file_system: Add `lifecycle_policy.transition_to_archive` attribute +``` \ No newline at end of file diff --git a/internal/service/efs/file_system.go b/internal/service/efs/file_system.go index 62e21b2db6e..da404602c99 100644 --- a/internal/service/efs/file_system.go +++ b/internal/service/efs/file_system.go @@ -88,6 +88,11 @@ func ResourceFileSystem() *schema.Resource { MaxItems: 2, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "transition_to_archive": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(efs.TransitionToArchiveRules_Values(), false), + }, "transition_to_ia": { Type: schema.TypeString, Optional: true, @@ -475,6 +480,10 @@ func flattenFileSystemLifecyclePolicies(apiObjects []*efs.LifecyclePolicy) []int tfMap := make(map[string]interface{}) + if apiObject.TransitionToArchive != nil { + tfMap["transition_to_archive"] = aws.StringValue(apiObject.TransitionToArchive) + } + if apiObject.TransitionToIA != nil { tfMap["transition_to_ia"] = aws.StringValue(apiObject.TransitionToIA) } @@ -501,6 +510,10 @@ func expandFileSystemLifecyclePolicies(tfList []interface{}) []*efs.LifecyclePol apiObject := &efs.LifecyclePolicy{} + if v, ok := tfMap["transition_to_archive"].(string); ok && v != "" { + apiObject.TransitionToArchive = aws.String(v) + } + if v, ok := tfMap["transition_to_ia"].(string); ok && v != "" { apiObject.TransitionToIA = aws.String(v) } diff --git a/internal/service/efs/file_system_data_source.go b/internal/service/efs/file_system_data_source.go index 397629a6edd..ff614d0a350 100644 --- a/internal/service/efs/file_system_data_source.go +++ b/internal/service/efs/file_system_data_source.go @@ -65,6 +65,10 @@ func DataSourceFileSystem() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "transition_to_archive": { + Type: schema.TypeString, + Computed: true, + }, "transition_to_ia": { Type: schema.TypeString, Computed: true, diff --git a/internal/service/efs/file_system_test.go b/internal/service/efs/file_system_test.go index d2c4f7d6715..2f62d88e30f 100644 --- a/internal/service/efs/file_system_test.go +++ b/internal/service/efs/file_system_test.go @@ -351,7 +351,9 @@ func TestAccEFSFileSystem_lifecyclePolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFileSystem(ctx, resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "1"), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_archive", ""), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_ia", efs.TransitionToIARulesAfter30Days), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_primary_storage_class", ""), ), }, { @@ -367,6 +369,8 @@ func TestAccEFSFileSystem_lifecyclePolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFileSystem(ctx, resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "1"), + 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), ), }, @@ -387,8 +391,30 @@ func TestAccEFSFileSystem_lifecyclePolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFileSystem(ctx, resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "2"), + 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", ""), + ), + }, + { + Config: testAccFileSystemConfig_lifecyclePolicyTransitionToArchive( + "transition_to_ia", + efs.TransitionToIARulesAfter30Days, + "transition_to_archive", + efs.TransitionToArchiveRulesAfter60Days, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckFileSystem(ctx, resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "2"), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_archive", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_ia", efs.TransitionToIARulesAfter30Days), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_primary_storage_class", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_archive", efs.TransitionToArchiveRulesAfter60Days), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_ia", ""), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_primary_storage_class", ""), ), }, }, @@ -426,9 +452,6 @@ func testAccCheckFileSystem(ctx context.Context, n string, v *efs.FileSystemDesc if !ok { return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No EFS file system ID is set") - } conn := acctest.Provider.Meta().(*conns.AWSClient).EFSConn(ctx) @@ -624,6 +647,22 @@ resource "aws_efs_file_system" "test" { `, lpName1, lpVal1, lpName2, lpVal2) } +func testAccFileSystemConfig_lifecyclePolicyTransitionToArchive(lpName1, lpVal1, lpName2, lpVal2 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 + } +} +`, lpName1, lpVal1, lpName2, lpVal2) +} + const testAccFileSystemConfig_removedLifecyclePolicy = ` 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 58fb7fe21dd..d3791a33b31 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -59,6 +59,7 @@ user guide for more information. * `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`. * `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`. ## Attribute Reference