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

r/aws_efs_file_system - refactor tagging and tests #11654

Merged
merged 3 commits into from
Jan 24, 2020
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
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 @@ -381,8 +381,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 @@ -472,7 +470,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 @@ -625,8 +623,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