Skip to content

Commit

Permalink
resource/aws_efs_file_system: Refactor tagging to standardized TagRes…
Browse files Browse the repository at this point in the history
…ource/UntagResource calls, SDK constants, and tests (#11654)

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSEFSFileSystem_kmsConfigurationWithoutEncryption (25.32s)
--- PASS: TestAccAWSEFSFileSystem_pagedTags (45.14s)
--- PASS: TestAccAWSEFSFileSystem_ThroughputMode (53.13s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy (67.97s)
--- PASS: TestAccAWSEFSFileSystem_basic (70.60s)
--- PASS: TestAccAWSEFSFileSystem_kmsKey (75.09s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_removal (80.93s)
--- PASS: TestAccAWSEFSFileSystem_disappears (85.33s)
--- PASS: TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps (106.19s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_update (127.86s)
--- PASS: TestAccAWSEFSFileSystem_tags (128.90s)
```

Output from acceptance testing in AWS GovCloud (US) (unrelated test failure fix noted in the review):

```
--- PASS: TestAccAWSEFSFileSystem_kmsConfigurationWithoutEncryption (24.79s)
--- FAIL: TestAccAWSEFSFileSystem_basic (27.99s)
--- PASS: TestAccAWSEFSFileSystem_disappears (30.58s)
--- PASS: TestAccAWSEFSFileSystem_kmsKey (49.76s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_removal (53.12s)
--- PASS: TestAccAWSEFSFileSystem_tags (62.95s)
--- PASS: TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps (81.86s)
--- PASS: TestAccAWSEFSFileSystem_ThroughputMode (87.62s)
--- PASS: TestAccAWSEFSFileSystem_pagedTags (90.78s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy (117.45s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_update (123.65s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Jan 24, 2020
1 parent 3b83218 commit d46cb8a
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 141 deletions.
6 changes: 1 addition & 5 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ func ServiceTagFunction(serviceName string) string {
return "AddTagsToResource"
case "ec2":
return "CreateTags"
case "efs":
return "CreateTags"
case "elasticache":
return "AddTagsToResource"
case "elasticbeanstalk":
Expand Down Expand Up @@ -424,7 +422,7 @@ func ServiceTagInputIdentifierField(serviceName string) string {
case "ec2":
return "Resources"
case "efs":
return "FileSystemId"
return "ResourceId"
case "elasticache":
return "ResourceName"
case "elasticsearchservice":
Expand Down Expand Up @@ -577,8 +575,6 @@ func ServiceUntagFunction(serviceName string) string {
return "RemoveTagsFromResource"
case "ec2":
return "DeleteTags"
case "efs":
return "DeleteTags"
case "elasticache":
return "RemoveTagsFromResource"
case "elasticbeanstalk":
Expand Down
16 changes: 8 additions & 8 deletions aws/internal/keyvaluetags/update_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 6 additions & 14 deletions aws/resource_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -263,7 +262,7 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro
FileSystemId: aws.String(d.Id()),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "FileSystemNotFound" {
if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") {
log.Printf("[WARN] EFS file system (%s) could not be found.", d.Id())
d.SetId("")
return nil
Expand All @@ -275,16 +274,6 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("EFS file system %q could not be found.", d.Id())
}

tags, err := keyvaluetags.EfsListTags(conn, 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 resp.FileSystems {
if d.Id() == *f.FileSystemId {
Expand Down Expand Up @@ -314,6 +303,10 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro
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)
}

region := meta.(*AWSClient).region
if err := d.Set("dns_name", resourceAwsEfsDnsName(aws.StringValue(fs.FileSystemId), region)); err != nil {
return fmt.Errorf("error setting dns_name: %s", err)
Expand Down Expand Up @@ -363,8 +356,7 @@ func waitForDeleteEfsFileSystem(conn *efs.EFS, id string, timeout time.Duration)
FileSystemId: aws.String(id),
})
if err != nil {
efsErr, ok := err.(awserr.Error)
if ok && efsErr.Code() == "FileSystemNotFound" {
if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") {
return nil, "", nil
}
return nil, "error", err
Expand Down
Loading

0 comments on commit d46cb8a

Please sign in to comment.