Skip to content

Commit

Permalink
r/aws_efs_file_system: Support single Availability Zone storage classes
Browse files Browse the repository at this point in the history
  • Loading branch information
shuheiktgw committed Mar 21, 2021
1 parent 7141d1c commit 1ed36db
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
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/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

0 comments on commit 1ed36db

Please sign in to comment.