diff --git a/.changelog/33243.txt b/.changelog/33243.txt new file mode 100644 index 00000000000..83a18af2e8b --- /dev/null +++ b/.changelog/33243.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_efs_file_system: Add `name` attribute +``` + +```release-note:enhancement +data-source/aws_efs_file_system: Add `name` attribute +``` \ No newline at end of file diff --git a/internal/service/efs/file_system.go b/internal/service/efs/file_system.go index b1dfa1b1183..5ebfc5e81db 100644 --- a/internal/service/efs/file_system.go +++ b/internal/service/efs/file_system.go @@ -99,6 +99,10 @@ func ResourceFileSystem() *schema.Resource { }, }, }, + "name": { + Type: schema.TypeString, + Computed: true, + }, "number_of_mount_targets": { Type: schema.TypeInt, Computed: true, @@ -153,14 +157,13 @@ func ResourceFileSystem() *schema.Resource { func resourceFileSystemCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).EFSConn(ctx) - creationToken := "" + var creationToken string if v, ok := d.GetOk("creation_token"); ok { creationToken = v.(string) } else { creationToken = id.UniqueId() } throughputMode := d.Get("throughput_mode").(string) - input := &efs.CreateFileSystemInput{ CreationToken: aws.String(creationToken), Tags: getTagsIn(ctx), @@ -242,17 +245,17 @@ func resourceFileSystemRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("dns_name", meta.(*conns.AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) d.Set("encrypted", fs.Encrypted) d.Set("kms_key_id", fs.KmsKeyId) + d.Set("name", fs.Name) d.Set("number_of_mount_targets", fs.NumberOfMountTargets) d.Set("owner_id", fs.OwnerId) d.Set("performance_mode", fs.PerformanceMode) d.Set("provisioned_throughput_in_mibps", fs.ProvisionedThroughputInMibps) - d.Set("throughput_mode", fs.ThroughputMode) - - setTagsOut(ctx, fs.Tags) - if err := d.Set("size_in_bytes", flattenFileSystemSizeInBytes(fs.SizeInBytes)); err != nil { return diag.Errorf("setting size_in_bytes: %s", err) } + d.Set("throughput_mode", fs.ThroughputMode) + + setTagsOut(ctx, fs.Tags) output, err := conn.DescribeLifecycleConfigurationWithContext(ctx, &efs.DescribeLifecycleConfigurationInput{ FileSystemId: aws.String(d.Id()), @@ -274,7 +277,6 @@ func resourceFileSystemUpdate(ctx context.Context, d *schema.ResourceData, meta if d.HasChanges("provisioned_throughput_in_mibps", "throughput_mode") { throughputMode := d.Get("throughput_mode").(string) - input := &efs.UpdateFileSystemInput{ FileSystemId: aws.String(d.Id()), ThroughputMode: aws.String(throughputMode), diff --git a/internal/service/efs/file_system_data_source.go b/internal/service/efs/file_system_data_source.go index 251e1d23e47..3ac3df9dafc 100644 --- a/internal/service/efs/file_system_data_source.go +++ b/internal/service/efs/file_system_data_source.go @@ -6,7 +6,6 @@ package efs import ( "context" "fmt" - "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/efs" @@ -42,6 +41,10 @@ func DataSourceFileSystem() *schema.Resource { Computed: true, ValidateFunc: validation.StringLenBetween(0, 64), }, + "dns_name": { + Type: schema.TypeString, + Computed: true, + }, "encrypted": { Type: schema.TypeBool, Computed: true, @@ -55,16 +58,27 @@ func DataSourceFileSystem() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "performance_mode": { - Type: schema.TypeString, + "lifecycle_policy": { + Type: schema.TypeList, Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "transition_to_ia": { + Type: schema.TypeString, + Computed: true, + }, + "transition_to_primary_storage_class": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, }, - "dns_name": { + "name": { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchemaComputed(), - "throughput_mode": { + "performance_mode": { Type: schema.TypeString, Computed: true, }, @@ -76,21 +90,10 @@ func DataSourceFileSystem() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "lifecycle_policy": { - Type: schema.TypeList, + "tags": tftags.TagsSchemaComputed(), + "throughput_mode": { + Type: schema.TypeString, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "transition_to_ia": { - Type: schema.TypeString, - Computed: true, - }, - "transition_to_primary_storage_class": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, }, }, } @@ -113,7 +116,6 @@ func dataSourceFileSystemRead(ctx context.Context, d *schema.ResourceData, meta describeEfsOpts.FileSystemId = aws.String(v.(string)) } - log.Printf("[DEBUG] Reading EFS File System: %s", describeEfsOpts) describeResp, err := conn.DescribeFileSystemsWithContext(ctx, describeEfsOpts) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EFS FileSystem: %s", err) @@ -148,19 +150,21 @@ func dataSourceFileSystemRead(ctx context.Context, d *schema.ResourceData, meta fs := results[0] d.SetId(aws.StringValue(fs.FileSystemId)) + d.Set("arn", fs.FileSystemArn) 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) - d.Set("arn", fs.FileSystemArn) + d.Set("dns_name", meta.(*conns.AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) d.Set("file_system_id", fs.FileSystemId) d.Set("encrypted", fs.Encrypted) d.Set("kms_key_id", fs.KmsKeyId) + d.Set("name", fs.Name) + d.Set("performance_mode", fs.PerformanceMode) d.Set("provisioned_throughput_in_mibps", fs.ProvisionedThroughputInMibps) - d.Set("throughput_mode", fs.ThroughputMode) if fs.SizeInBytes != nil { d.Set("size_in_bytes", fs.SizeInBytes.Value) } + d.Set("throughput_mode", fs.ThroughputMode) if err := d.Set("tags", KeyValueTags(ctx, fs.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) @@ -178,7 +182,5 @@ func dataSourceFileSystemRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "setting lifecycle_policy: %s", err) } - d.Set("dns_name", meta.(*conns.AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) - return diags } diff --git a/internal/service/efs/file_system_data_source_test.go b/internal/service/efs/file_system_data_source_test.go index 371b822e179..71bb2230fea 100644 --- a/internal/service/efs/file_system_data_source_test.go +++ b/internal/service/efs/file_system_data_source_test.go @@ -11,7 +11,6 @@ import ( "github.com/aws/aws-sdk-go/service/efs" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" ) @@ -28,7 +27,6 @@ func TestAccEFSFileSystemDataSource_id(t *testing.T) { { Config: testAccFileSystemDataSourceConfig_id, Check: resource.ComposeTestCheckFunc( - testAccFileSystemCheckDataSource(dataSourceName, resourceName), resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"), resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"), @@ -36,6 +34,7 @@ func TestAccEFSFileSystemDataSource_id(t *testing.T) { 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, "name", resourceName, "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"), @@ -59,7 +58,6 @@ func TestAccEFSFileSystemDataSource_tags(t *testing.T) { { Config: testAccFileSystemDataSourceConfig_tags, Check: resource.ComposeTestCheckFunc( - testAccFileSystemCheckDataSource(dataSourceName, resourceName), resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"), resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"), @@ -67,6 +65,7 @@ func TestAccEFSFileSystemDataSource_tags(t *testing.T) { 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, "name", resourceName, "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"), @@ -90,7 +89,6 @@ func TestAccEFSFileSystemDataSource_name(t *testing.T) { { Config: testAccFileSystemDataSourceConfig_name, Check: resource.ComposeTestCheckFunc( - testAccFileSystemCheckDataSource(dataSourceName, resourceName), resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"), resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"), @@ -121,7 +119,6 @@ func TestAccEFSFileSystemDataSource_availabilityZone(t *testing.T) { { Config: testAccFileSystemDataSourceConfig_availabilityZone, Check: resource.ComposeTestCheckFunc( - testAccFileSystemCheckDataSource(dataSourceName, resourceName), resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_id", resourceName, "availability_zone_id"), resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_name", resourceName, "availability_zone_name"), ), @@ -155,40 +152,6 @@ func TestAccEFSFileSystemDataSource_nonExistent_tags(t *testing.T) { }) } -func testAccFileSystemCheckDataSource(dName, rName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[dName] - if !ok { - return fmt.Errorf("root module has no resource called %s", dName) - } - - efsRs, ok := s.RootModule().Resources[rName] - if !ok { - return fmt.Errorf("can't find aws_efs_file_system.test in state") - } - - attr := rs.Primary.Attributes - - if attr["creation_token"] != efsRs.Primary.Attributes["creation_token"] { - return fmt.Errorf( - "creation_token is %s; want %s", - attr["creation_token"], - efsRs.Primary.Attributes["creation_token"], - ) - } - - if attr["id"] != efsRs.Primary.Attributes["id"] { - return fmt.Errorf( - "file_system_id is %s; want %s", - attr["id"], - efsRs.Primary.Attributes["id"], - ) - } - - return nil - } -} - func testAccFileSystemConfig_dataSourceBasic(rName string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { diff --git a/internal/service/efs/file_system_test.go b/internal/service/efs/file_system_test.go index bd204d96d93..d2c4f7d6715 100644 --- a/internal/service/efs/file_system_test.go +++ b/internal/service/efs/file_system_test.go @@ -39,6 +39,7 @@ func TestAccEFSFileSystem_basic(t *testing.T) { acctest.MatchResourceAttrRegionalHostname(resourceName, "dns_name", "efs", regexache.MustCompile(`fs-[^.]+`)), resource.TestCheckResourceAttr(resourceName, "encrypted", "false"), resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "0"), + resource.TestCheckResourceAttr(resourceName, "name", ""), resource.TestCheckResourceAttr(resourceName, "number_of_mount_targets", "0"), acctest.MatchResourceAttrAccountID(resourceName, "owner_id"), resource.TestCheckResourceAttr(resourceName, "performance_mode", "generalPurpose"), @@ -218,8 +219,11 @@ func TestAccEFSFileSystem_kmsKey(t *testing.T) { Config: testAccFileSystemConfig_kmsKey(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckFileSystem(ctx, resourceName, &desc), - resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "encrypted", "true"), + resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), ), }, { @@ -571,6 +575,10 @@ resource "aws_kms_key" "test" { resource "aws_efs_file_system" "test" { encrypted = %[2]t kms_key_id = aws_kms_key.test.arn + + tags = { + Name = %[1]q + } } `, rName, enable) } diff --git a/website/docs/d/efs_file_system.html.markdown b/website/docs/d/efs_file_system.html.markdown index f2aca308f7f..cfb64e9450a 100644 --- a/website/docs/d/efs_file_system.html.markdown +++ b/website/docs/d/efs_file_system.html.markdown @@ -48,6 +48,7 @@ This data source exports the following attributes in addition to the arguments a * `encrypted` - Whether EFS is encrypted. * `kms_key_id` - ARN for the KMS encryption key. * `lifecycle_policy` - File system [lifecycle policy](https://docs.aws.amazon.com/efs/latest/ug/API_LifecyclePolicy.html) object. +* `name` - The value of the file system's `Name` tag. * `performance_mode` - 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 map of tags to assign to the file system. diff --git a/website/docs/r/efs_file_system.html.markdown b/website/docs/r/efs_file_system.html.markdown index 8c410eb6f32..323a0f09536 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -68,8 +68,9 @@ This resource exports the following attributes in addition to the arguments abov * `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). -* `owner_id` - The AWS account that created the file system. If the file system was createdby an IAM user, the parent account to which the user belongs is the owner. +* `name` - The value of the file system's `Name` tag. * `number_of_mount_targets` - The current number of mount targets that the file system has. +* `owner_id` - The AWS account that created the file system. If the file system was createdby an IAM user, the parent account to which the user belongs is the owner. * `size_in_bytes` - The latest known metered size (in bytes) of data stored in the file system, the value is not the exact size that the file system was at any point in time. See [Size In Bytes](#size-in-bytes). * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).