Skip to content

Commit

Permalink
Merge pull request #20971 from DrFaust92/efs_fix_lifecycle
Browse files Browse the repository at this point in the history
rd/efs_file_system - support multiple lifecycle policies
  • Loading branch information
ewbankkit authored Sep 22, 2021
2 parents bda226f + 84df964 commit c8fdd1f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changelog/20971.txt
Original file line number Diff line number Diff line change
@@ -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`.
```
16 changes: 5 additions & 11 deletions aws/data_source_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,6 +78,10 @@ func dataSourceAwsEfsFileSystem() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"transition_to_primary_storage_class": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 31 additions & 1 deletion aws/resource_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
},
Expand All @@ -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),
),
},
Expand All @@ -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),
),
},
},
})
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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" {}
`

0 comments on commit c8fdd1f

Please sign in to comment.