diff --git a/.changelog/20971.txt b/.changelog/20971.txt new file mode 100644 index 00000000000..601d97f58f9 --- /dev/null +++ b/.changelog/20971.txt @@ -0,0 +1,7 @@ +```release-note:bug +resource/efs_file_system: Allow multiple lifecycle policies. +``` + +```release-note:enhancement +data-source/efs_file_system: Add `transition_to_primary_storage_class` to `lifecycle_policy`. +``` \ No newline at end of file diff --git a/aws/data_source_aws_efs_file_system.go b/aws/data_source_aws_efs_file_system.go index 892898a1302..a5e96228838 100644 --- a/aws/data_source_aws_efs_file_system.go +++ b/aws/data_source_aws_efs_file_system.go @@ -6,7 +6,6 @@ import ( "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/efs" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -79,6 +78,10 @@ func dataSourceAwsEfsFileSystem() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "transition_to_primary_storage_class": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -145,16 +148,7 @@ func dataSourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) er d.Set("availability_zone_name", fs.AvailabilityZoneName) d.Set("creation_token", fs.CreationToken) d.Set("performance_mode", fs.PerformanceMode) - - fsARN := arn.ARN{ - AccountID: meta.(*AWSClient).accountid, - Partition: meta.(*AWSClient).partition, - Region: meta.(*AWSClient).region, - Resource: fmt.Sprintf("file-system/%s", aws.StringValue(fs.FileSystemId)), - Service: "elasticfilesystem", - }.String() - - d.Set("arn", fsARN) + d.Set("arn", fs.FileSystemArn) d.Set("file_system_id", fs.FileSystemId) d.Set("encrypted", fs.Encrypted) d.Set("kms_key_id", fs.KmsKeyId) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 3b599084c4f..31466590fe2 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -110,7 +110,7 @@ func resourceAwsEfsFileSystem() *schema.Resource { "lifecycle_policy": { Type: schema.TypeList, Optional: true, - MaxItems: 1, + MaxItems: 2, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "transition_to_ia": { diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 9c61b0db765..53bd923f5dc 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -360,6 +360,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { ), Check: resource.ComposeTestCheckFunc( testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_ia", efs.TransitionToIARulesAfter30Days), ), }, @@ -375,6 +376,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { ), Check: resource.ComposeTestCheckFunc( testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "1"), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_primary_storage_class", efs.TransitionToPrimaryStorageClassRulesAfter1Access), ), }, @@ -385,6 +387,20 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "0"), ), }, + { + Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicyMulti( + "transition_to_primary_storage_class", + efs.TransitionToPrimaryStorageClassRulesAfter1Access, + "transition_to_ia", + efs.TransitionToIARulesAfter30Days, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "2"), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.0.transition_to_primary_storage_class", efs.TransitionToPrimaryStorageClassRulesAfter1Access), + resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.1.transition_to_ia", efs.TransitionToIARulesAfter30Days), + ), + }, }, }) } @@ -625,7 +641,7 @@ resource "aws_efs_file_system" "test" { `, provisionedThroughputInMibps) } -func testAccAWSEFSFileSystemConfigWithLifecyclePolicy(lpName string, lpVal string) string { +func testAccAWSEFSFileSystemConfigWithLifecyclePolicy(lpName, lpVal string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { lifecycle_policy { @@ -635,6 +651,20 @@ resource "aws_efs_file_system" "test" { `, lpName, lpVal) } +func testAccAWSEFSFileSystemConfigWithLifecyclePolicyMulti(lpName1, lpVal1, lpName2, lpVal2 string) string { + return fmt.Sprintf(` +resource "aws_efs_file_system" "test" { + lifecycle_policy { + %[1]s = %[2]q + } + + lifecycle_policy { + %[3]s = %[4]q + } +} +`, lpName1, lpVal1, lpName2, lpVal2) +} + const testAccAWSEFSFileSystemConfigRemovedLifecyclePolicy = ` resource "aws_efs_file_system" "test" {} `