Skip to content

Commit

Permalink
data-source/aws_efs_file_system: Add throughput_mode, `provisioned_…
Browse files Browse the repository at this point in the history
…throughput_in_mibps`, and `lifecycle_policy` attributes (#11647)

Output from acceptance testing:

```
--- PASS: TestAccDataSourceAwsEfsFileSystem_id (16.28s)
--- PASS: TestAccDataSourceAwsEfsFileSystem_name (16.30s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Jan 24, 2020
1 parent c04a8df commit edebc20
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 26 deletions.
48 changes: 38 additions & 10 deletions aws/data_source_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ func dataSourceAwsEfsFileSystem() *schema.Resource {
Computed: true,
},
"tags": tagsSchemaComputed(),
"throughput_mode": {
Type: schema.TypeString,
Computed: true,
},
"provisioned_throughput_in_mibps": {
Type: schema.TypeFloat,
Computed: true,
},
"lifecycle_policy": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"transition_to_ia": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -79,16 +100,6 @@ func dataSourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) er

d.SetId(*describeResp.FileSystems[0].FileSystemId)

tags, err := keyvaluetags.EfsListTags(efsconn, d.Id())

if err != nil {
return fmt.Errorf("error listing tags for EFS file system (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error settings tags: %s", err)
}

var fs *efs.FileSystemDescription
for _, f := range describeResp.FileSystems {
if d.Id() == *f.FileSystemId {
Expand Down Expand Up @@ -117,6 +128,23 @@ func dataSourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) er
d.Set("file_system_id", fs.FileSystemId)
d.Set("encrypted", fs.Encrypted)
d.Set("kms_key_id", fs.KmsKeyId)
d.Set("provisioned_throughput_in_mibps", fs.ProvisionedThroughputInMibps)
d.Set("throughput_mode", fs.ThroughputMode)

if err := d.Set("tags", keyvaluetags.EfsKeyValueTags(fs.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

res, err := efsconn.DescribeLifecycleConfiguration(&efs.DescribeLifecycleConfigurationInput{
FileSystemId: fs.FileSystemId,
})
if err != nil {
return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %s",
aws.StringValue(fs.FileSystemId), err)
}
if err := resourceAwsEfsFileSystemSetLifecyclePolicy(d, res.LifecyclePolicies); err != nil {
return err
}

region := meta.(*AWSClient).region
err = d.Set("dns_name", resourceAwsEfsDnsName(*fs.FileSystemId, region))
Expand Down
72 changes: 56 additions & 16 deletions aws/data_source_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,76 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccDataSourceAwsEfsFileSystem(t *testing.T) {
func TestAccDataSourceAwsEfsFileSystem_id(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) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEfsFileSystemConfig,
Config: testAccDataSourceAwsEfsFileSystemIDConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.aws_efs_file_system.by_id", "arn", "aws_efs_file_system.test", "arn"),
testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_creation_token"),
testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_id"),
resource.TestMatchResourceAttr("data.aws_efs_file_system.by_creation_token", "dns_name", regexp.MustCompile(`^[^.]+.efs.([a-z]{2}-(gov-)?[a-z]+-\d{1})?.amazonaws.com$`)),
resource.TestMatchResourceAttr("data.aws_efs_file_system.by_id", "dns_name", regexp.MustCompile(`^[^.]+.efs.([a-z]{2}-(gov-)?[a-z]+-\d{1})?.amazonaws.com$`)),
testAccDataSourceAwsEfsFileSystemCheck(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"),
resource.TestCheckResourceAttrPair(dataSourceName, "encrypted", resourceName, "encrypted"),
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_id", resourceName, "kms_key_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags", resourceName, "tags"),
resource.TestCheckResourceAttrPair(dataSourceName, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "provisioned_throughput_in_mibps", resourceName, "provisioned_throughput_in_mibps"),
resource.TestCheckResourceAttrPair(dataSourceName, "throughput_mode", resourceName, "throughput_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "lifecycle_policy", resourceName, "lifecycle_policy"),
),
},
},
})
}

func testAccDataSourceAwsEfsFileSystemCheck(name string) resource.TestCheckFunc {
func TestAccDataSourceAwsEfsFileSystem_name(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) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEfsFileSystemNameConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsEfsFileSystemCheck(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"),
resource.TestCheckResourceAttrPair(dataSourceName, "encrypted", resourceName, "encrypted"),
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_id", resourceName, "kms_key_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags", resourceName, "tags"),
resource.TestCheckResourceAttrPair(dataSourceName, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "provisioned_throughput_in_mibps", resourceName, "provisioned_throughput_in_mibps"),
resource.TestCheckResourceAttrPair(dataSourceName, "throughput_mode", resourceName, "throughput_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "lifecycle_policy", resourceName, "lifecycle_policy"),
),
},
},
})
}

func testAccDataSourceAwsEfsFileSystemCheck(dName, rName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
rs, ok := s.RootModule().Resources[dName]
if !ok {
return fmt.Errorf("root module has no resource called %s", name)
return fmt.Errorf("root module has no resource called %s", dName)
}

efsRs, ok := s.RootModule().Resources["aws_efs_file_system.test"]
efsRs, ok := s.RootModule().Resources[rName]
if !ok {
return fmt.Errorf("can't find aws_efs_file_system.test in state")
}
Expand All @@ -62,14 +98,18 @@ func testAccDataSourceAwsEfsFileSystemCheck(name string) resource.TestCheckFunc
}
}

const testAccDataSourceAwsEfsFileSystemConfig = `
const testAccDataSourceAwsEfsFileSystemNameConfig = `
resource "aws_efs_file_system" "test" {}
data "aws_efs_file_system" "by_creation_token" {
creation_token = "${aws_efs_file_system.test.creation_token}"
data "aws_efs_file_system" "test" {
creation_token = "${aws_efs_file_system.test.creation_token}"
}
`

const testAccDataSourceAwsEfsFileSystemIDConfig = `
resource "aws_efs_file_system" "test" {}
data "aws_efs_file_system" "by_id" {
data "aws_efs_file_system" "test" {
file_system_id = "${aws_efs_file_system.test.id}"
}
`
7 changes: 7 additions & 0 deletions website/docs/d/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The following arguments are supported:
* `file_system_id` - (Optional) The ID that identifies the file system (e.g. fs-ccfc0d65).
* `creation_token` - (Optional) Restricts the list to the file system with this creation token.


## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand All @@ -40,3 +41,9 @@ In addition to all arguments above, the following attributes are exported:
* `encrypted` - Whether EFS is encrypted.
* `kms_key_id` - The ARN for the KMS encryption key.
* `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).
* `lifecycle_policy` - A file system [lifecycle policy](https://docs.aws.amazon.com/efs/latest/ug/API_LifecyclePolicy.html) object.
* `performance_mode` - The file system performance mode.
* `provisioned_throughput_in_mibps` - The throughput, measured in MiB/s, that you want to provision for the file system.
* `tags` -A mapping of tags to assign to the file system.
* `throughput_mode` - Throughput mode for the file system.

0 comments on commit edebc20

Please sign in to comment.