From 1ed36db79ad627e9ac08aa6bbaabb7a00696e04c Mon Sep 17 00:00:00 2001 From: shuheiktgw Date: Sun, 21 Mar 2021 15:37:14 +0900 Subject: [PATCH 1/3] r/aws_efs_file_system: Support single Availability Zone storage classes --- aws/resource_aws_efs_file_system.go | 19 ++++++++ aws/resource_aws_efs_file_system_test.go | 47 ++++++++++++++++++++ website/docs/r/efs_file_system.html.markdown | 2 + 3 files changed, 68 insertions(+) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 3ee30becd2b..9e0dd81f12e 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -32,6 +32,19 @@ func resourceAwsEfsFileSystem() *schema.Resource { Computed: true, }, + "availability_zone_id": { + Type: schema.TypeString, + Computed: true, + }, + + "availability_zone_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "creation_token": { Type: schema.TypeString, Optional: true, @@ -129,6 +142,10 @@ func resourceAwsEfsFileSystemCreate(d *schema.ResourceData, meta interface{}) er Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().EfsTags(), } + if v, ok := d.GetOk("availability_zone_name"); ok { + createOpts.AvailabilityZoneName = aws.String(v.(string)) + } + if v, ok := d.GetOk("performance_mode"); ok { createOpts.PerformanceMode = aws.String(v.(string)) } @@ -299,6 +316,8 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro }.String() d.Set("arn", fsARN) + d.Set("availability_zone_id", fs.AvailabilityZoneId) + d.Set("availability_zone_name", fs.AvailabilityZoneName) d.Set("creation_token", fs.CreationToken) d.Set("encrypted", fs.Encrypted) d.Set("kms_key_id", fs.KmsKeyId) diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 282287d6414..a4ba3997e98 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -124,6 +124,35 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { }) } +func TestAccAWSEFSFileSystem_availabilityZoneName(t *testing.T) { + var desc efs.FileSystemDescription + resourceName := "aws_efs_file_system.test" + rName := acctest.RandomWithPrefix("tf-acc") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, efs.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckEfsFileSystemDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEFSFileSystemConfigAvailabilityZoneName(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"), + resource.TestCheckResourceAttrSet(resourceName, "availability_zone_name"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"creation_token"}, + }, + }, + }) +} + func TestAccAWSEFSFileSystem_tags(t *testing.T) { var desc efs.FileSystemDescription rName := acctest.RandomWithPrefix("tf-acc-tags") @@ -641,6 +670,24 @@ resource "aws_efs_file_system" "test" { `, rName) } +func testAccAWSEFSFileSystemConfigAvailabilityZoneName(rName string) string { + return fmt.Sprintf(` +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + +resource "aws_efs_file_system" "test" { + creation_token = %q + availability_zone_name = data.aws_availability_zones.available.names[0] +} +`, rName) +} + func testAccAWSEFSFileSystemConfigTags1(rName, tagKey1, tagValue1 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 bdda69f1c48..4ea037fac89 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -40,6 +40,7 @@ resource "aws_efs_file_system" "foo_with_lifecyle_policy" { The following arguments are supported: +* `availability_zone_name` - (Optional) the AWS Availability Zone in which to create the file system. Used to create a file system that uses One Zone storage classes. See [user guide](https://docs.aws.amazon.com/efs/latest/ug/storage-classes.html) for more information. * `creation_token` - (Optional) A unique name (a maximum of 64 characters are allowed) used as reference when creating the Elastic File System to ensure idempotent file system creation. By default generated by Terraform. See [Elastic File System] @@ -62,6 +63,7 @@ For **lifecycle_policy** the following attributes are supported: In addition to all arguments above, the following attributes are exported: * `arn` - Amazon Resource Name of the file system. +* `availability_zone_id` - The identifier of the Availability Zone in which the file system's One Zone storage classes exist. * `id` - The ID that identifies the file system (e.g. fs-ccfc0d65). * `dns_name` - The DNS name for the filesystem per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html). From 9a315f3ef98b9df663dad158cf0af38b2013962d Mon Sep 17 00:00:00 2001 From: shuheiktgw Date: Sun, 21 Mar 2021 15:37:34 +0900 Subject: [PATCH 2/3] d/aws_efs_file_system: Support single Availability Zone storage classes --- aws/data_source_aws_efs_file_system.go | 10 +++++ aws/data_source_aws_efs_file_system_test.go | 40 ++++++++++++++++++++ website/docs/d/efs_file_system.html.markdown | 2 + 3 files changed, 52 insertions(+) diff --git a/aws/data_source_aws_efs_file_system.go b/aws/data_source_aws_efs_file_system.go index b544adac1fd..f68ccc11efb 100644 --- a/aws/data_source_aws_efs_file_system.go +++ b/aws/data_source_aws_efs_file_system.go @@ -22,6 +22,14 @@ func dataSourceAwsEfsFileSystem() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "availability_zone_id": { + Type: schema.TypeString, + Computed: true, + }, + "availability_zone_name": { + Type: schema.TypeString, + Computed: true, + }, "creation_token": { Type: schema.TypeString, Optional: true, @@ -109,6 +117,8 @@ func dataSourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) er fs := describeResp.FileSystems[0] d.SetId(aws.StringValue(fs.FileSystemId)) + d.Set("availability_zone_id", fs.AvailabilityZoneId) + d.Set("availability_zone_name", fs.AvailabilityZoneName) d.Set("creation_token", fs.CreationToken) d.Set("performance_mode", fs.PerformanceMode) diff --git a/aws/data_source_aws_efs_file_system_test.go b/aws/data_source_aws_efs_file_system_test.go index f74639d7176..08aa89d4a61 100644 --- a/aws/data_source_aws_efs_file_system_test.go +++ b/aws/data_source_aws_efs_file_system_test.go @@ -70,6 +70,27 @@ func TestAccDataSourceAwsEfsFileSystem_name(t *testing.T) { }) } +func TestAccDataSourceAwsEfsFileSystem_availabilityZone(t *testing.T) { + dataSourceName := "data.aws_efs_file_system.test" + resourceName := "aws_efs_file_system.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, efs.EndpointsID), + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsEfsFileSystemAvailabilityZoneConfig, + Check: resource.ComposeTestCheckFunc( + testAccDataSourceAwsEfsFileSystemCheck(dataSourceName, resourceName), + resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_id", resourceName, "availability_zone_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_name", resourceName, "availability_zone_name"), + ), + }, + }, + }) +} + func TestAccDataSourceAwsEfsFileSystem_NonExistent(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ @@ -140,3 +161,22 @@ data "aws_efs_file_system" "test" { file_system_id = aws_efs_file_system.test.id } ` + +const testAccDataSourceAwsEfsFileSystemAvailabilityZoneConfig = ` +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + +resource "aws_efs_file_system" "test" { + availability_zone_name = data.aws_availability_zones.available.names[0] +} + +data "aws_efs_file_system" "test" { + file_system_id = aws_efs_file_system.test.id +} +` diff --git a/website/docs/d/efs_file_system.html.markdown b/website/docs/d/efs_file_system.html.markdown index 0aef0be8548..c15aee5ae74 100644 --- a/website/docs/d/efs_file_system.html.markdown +++ b/website/docs/d/efs_file_system.html.markdown @@ -35,6 +35,8 @@ The following arguments are supported: In addition to all arguments above, the following attributes are exported: * `arn` - Amazon Resource Name of the file system. +* `availability_zone_name` - The Availability Zone name in which the file system's One Zone storage classes exist. +* `availability_zone_id` - The identifier of the Availability Zone in which the file system's One Zone storage classes exist. * `dns_name` - The DNS name for the filesystem per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html). * `encrypted` - Whether EFS is encrypted. * `kms_key_id` - The ARN for the KMS encryption key. From 59791af7b34051a3aea1a2dd03078844a7f44bfb Mon Sep 17 00:00:00 2001 From: shuheiktgw Date: Wed, 31 Mar 2021 08:46:35 +0900 Subject: [PATCH 3/3] aws_efs_file_system: Add change logs for the single AZ storage class support --- .changelog/18319.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/18319.txt diff --git a/.changelog/18319.txt b/.changelog/18319.txt new file mode 100644 index 00000000000..6e6e4eb0efc --- /dev/null +++ b/.changelog/18319.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +data-source/aws_efs_file_system: Add `availability_zone_id` and `availability_zone_name` attributes +``` + +```release-note:enhancement +resource/aws_efs_file_system: Add `availability_zone_id` attribute and `availability_zone_name` argument +``` \ No newline at end of file