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

add name attribute #33243

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changelog/33243.txt
Original file line number Diff line number Diff line change
@@ -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
```
16 changes: 9 additions & 7 deletions internal/service/efs/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func ResourceFileSystem() *schema.Resource {
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"number_of_mount_targets": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()),
Expand All @@ -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),
Expand Down
54 changes: 28 additions & 26 deletions internal/service/efs/file_system_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
},
},
},
},
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
41 changes: 2 additions & 39 deletions internal/service/efs/file_system_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -28,14 +27,14 @@ 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"),
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, "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"),
Expand All @@ -59,14 +58,14 @@ 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"),
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, "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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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" {
Expand Down
10 changes: 9 additions & 1 deletion internal/service/efs/file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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),
),
},
{
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down