Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_efs_file_system: Support single Availability Zone storage classes #18319

Merged
merged 4 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions aws/data_source_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func dataSourceAwsEfsFileSystem() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"availability_zone_id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shuheiktgw 👋 Can you please add changelog entries for these new schema attributes? Reference: https://github.com/hashicorp/terraform-provider-aws/blob/main/docs/contributing/pullrequest-submission-and-lifecycle.md#changelog-process

e.g. a new file called .changelog/18319.txt with contents:

```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
```

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I haven't noticed the new change log format! I'll fix it now!

Type: schema.TypeString,
Computed: true,
},
"availability_zone_name": {
Type: schema.TypeString,
Computed: true,
},
"creation_token": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -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)

Expand Down
40 changes: 40 additions & 0 deletions aws/data_source_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
`
19 changes: 19 additions & 0 deletions aws/resource_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions aws/resource_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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).

Expand Down