From e011036fef998848931c5d1f2d164d0ab1277f91 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 18 Jan 2020 09:23:01 +0200 Subject: [PATCH 1/3] refactor tag reading and skip list tag function refactor errors and use isAWSErr + enums refactor tests --- aws/resource_aws_efs_file_system.go | 20 +- aws/resource_aws_efs_file_system_test.go | 234 ++++++++++++----------- 2 files changed, 129 insertions(+), 125 deletions(-) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 5d2e49493f4..1a310d6ced1 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -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" @@ -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 @@ -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 { @@ -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) @@ -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 diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index e470d35ae1f..719e5c84162 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/efs" multierror "github.com/hashicorp/go-multierror" @@ -86,7 +85,7 @@ func TestResourceAWSEFSFileSystem_hasEmptyFileSystems(t *testing.T) { } func TestAccAWSEFSFileSystem_basic(t *testing.T) { - rInt := acctest.RandInt() + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -97,27 +96,12 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { { Config: testAccAWSEFSFileSystemConfig, Check: resource.ComposeTestCheckFunc( - testAccMatchResourceAttrRegionalARN("aws_efs_file_system.test", "arn", "elasticfilesystem", regexp.MustCompile(`file-system/fs-.+`)), - resource.TestCheckResourceAttr( - "aws_efs_file_system.test", - "performance_mode", - "generalPurpose"), - resource.TestCheckResourceAttr( - "aws_efs_file_system.test", - "throughput_mode", - efs.ThroughputModeBursting), - testAccCheckEfsFileSystem( - "aws_efs_file_system.test", - ), - testAccCheckEfsFileSystemPerformanceMode( - "aws_efs_file_system.test", - "generalPurpose", - ), - resource.TestMatchResourceAttr( - "aws_efs_file_system.test", - "dns_name", - regexp.MustCompile("^[^.]+.efs.us-west-2.amazonaws.com$"), - ), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "elasticfilesystem", regexp.MustCompile(`file-system/fs-.+`)), + resource.TestCheckResourceAttr(resourceName, "performance_mode", "generalPurpose"), + resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeBursting), + testAccCheckEfsFileSystem(resourceName, &desc), + testAccCheckEfsFileSystemPerformanceMode(resourceName, "generalPurpose"), + resource.TestMatchResourceAttr(resourceName, "dns_name", regexp.MustCompile("^[^.]+.efs.us-west-2.amazonaws.com$")), ), }, { @@ -127,50 +111,66 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { ImportStateVerifyIgnore: []string{"creation_token"}, }, { - Config: testAccAWSEFSFileSystemConfigWithTags(rInt), + Config: testAccAWSEFSFileSystemConfigWithPerformanceMode, Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem( - "aws_efs_file_system.test", - ), - testAccCheckEfsFileSystemPerformanceMode( - "aws_efs_file_system.test", - "generalPurpose", - ), - resource.TestCheckResourceAttr("aws_efs_file_system.test", "tags.%", "2"), - resource.TestCheckResourceAttr("aws_efs_file_system.test", "tags.Name", fmt.Sprintf("test-efs-%d", rInt)), - resource.TestCheckResourceAttr("aws_efs_file_system.test", "tags.Another", "tag"), + testAccCheckEfsFileSystem("aws_efs_file_system.test2", &desc), + testAccCheckEfsCreationToken("aws_efs_file_system.test2", "supercalifragilisticexpialidocious"), + testAccCheckEfsFileSystemPerformanceMode("aws_efs_file_system.test2", "maxIO"), ), }, + }, + }) +} + +func TestAccAWSEFSFileSystem_tags(t *testing.T) { + var desc efs.FileSystemDescription + rName := acctest.RandomWithPrefix("tf-acc") + resourceName := "aws_efs_file_system.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckEfsFileSystemDestroy, + Steps: []resource.TestStep{ { - Config: testAccAWSEFSFileSystemConfigWithMaxTags(rInt), + Config: testAccAWSEFSFileSystemConfigTags1(rName, "key1", "value1"), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem( - "aws_efs_file_system.test1", - ), - testAccCheckEfsFileSystemPerformanceMode( - "aws_efs_file_system.test1", - "generalPurpose", - ), - resource.TestCheckResourceAttr("aws_efs_file_system.test1", "tags.%", "50"), - resource.TestCheckResourceAttr("aws_efs_file_system.test1", "tags.Name", fmt.Sprintf("test-efs-%d", rInt)), - resource.TestCheckResourceAttr("aws_efs_file_system.test1", "tags.Another", "tag"), - resource.TestCheckResourceAttr("aws_efs_file_system.test1", "tags.Tag45", "TestTagValue"), + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), }, { - Config: testAccAWSEFSFileSystemConfigWithPerformanceMode, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"creation_token"}, + }, + { + Config: testAccAWSEFSFileSystemConfigTags2(rName, "key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem( - "aws_efs_file_system.test2", - ), - testAccCheckEfsCreationToken( - "aws_efs_file_system.test2", - "supercalifragilisticexpialidocious", - ), - testAccCheckEfsFileSystemPerformanceMode( - "aws_efs_file_system.test2", - "maxIO", - ), + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAWSEFSFileSystemConfigTags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAWSEFSFileSystemConfigWithMaxTags(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "50"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", rName), + resource.TestCheckResourceAttr(resourceName, "tags.Another", "tag"), + resource.TestCheckResourceAttr(resourceName, "tags.Tag45", "TestTagValue"), ), }, }, @@ -178,6 +178,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { } func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) { + var desc efs.FileSystemDescription rInt := acctest.RandInt() resourceName := "aws_efs_file_system.test" @@ -189,17 +190,8 @@ func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) { { Config: testAccAWSEFSFileSystemConfigPagedTags(rInt), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "aws_efs_file_system.test", - "tags.%", - "11"), - //testAccCheckEfsFileSystem( - // "aws_efs_file_system.test", - //), - //testAccCheckEfsFileSystemPerformanceMode( - // "aws_efs_file_system.test", - // "generalPurpose", - //), + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttr(resourceName, "tags.%", "11"), ), }, { @@ -213,6 +205,7 @@ func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) { } func TestAccAWSEFSFileSystem_kmsKey(t *testing.T) { + var desc efs.FileSystemDescription rInt := acctest.RandInt() kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_efs_file_system.test" @@ -225,8 +218,9 @@ func TestAccAWSEFSFileSystem_kmsKey(t *testing.T) { { Config: testAccAWSEFSFileSystemConfigWithKmsKey(rInt), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair("aws_efs_file_system.test", "kms_key_id", kmsKeyResourceName, "arn"), - resource.TestCheckResourceAttr("aws_efs_file_system.test", "encrypted", "true"), + testAccCheckEfsFileSystem(resourceName, &desc), + resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "encrypted", "true"), ), }, { @@ -256,6 +250,7 @@ func TestAccAWSEFSFileSystem_kmsConfigurationWithoutEncryption(t *testing.T) { } func TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps(t *testing.T) { + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -266,7 +261,7 @@ func TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps(t *testing.T) { { Config: testAccAWSEFSFileSystemConfig_ProvisionedThroughputInMibps(1.0), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "provisioned_throughput_in_mibps", "1"), resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeProvisioned), ), @@ -274,7 +269,7 @@ func TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps(t *testing.T) { { Config: testAccAWSEFSFileSystemConfig_ProvisionedThroughputInMibps(2.0), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "provisioned_throughput_in_mibps", "2"), resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeProvisioned), ), @@ -290,6 +285,7 @@ func TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps(t *testing.T) { } func TestAccAWSEFSFileSystem_ThroughputMode(t *testing.T) { + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -300,7 +296,7 @@ func TestAccAWSEFSFileSystem_ThroughputMode(t *testing.T) { { Config: testAccAWSEFSFileSystemConfig_ProvisionedThroughputInMibps(1.0), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "provisioned_throughput_in_mibps", "1"), resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeProvisioned), ), @@ -308,7 +304,7 @@ func TestAccAWSEFSFileSystem_ThroughputMode(t *testing.T) { { Config: testAccAWSEFSFileSystemConfig_ThroughputMode(efs.ThroughputModeBursting), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), resource.TestCheckResourceAttr(resourceName, "provisioned_throughput_in_mibps", "0"), resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeBursting), ), @@ -324,6 +320,7 @@ func TestAccAWSEFSFileSystem_ThroughputMode(t *testing.T) { } func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -344,7 +341,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { efs.TransitionToIARulesAfter30Days, ), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, "badExpectation"), ), ExpectError: regexp.MustCompile(`Expected: badExpectation`), @@ -355,7 +352,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { efs.TransitionToIARulesAfter30Days, ), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, efs.TransitionToIARulesAfter30Days), ), }, @@ -369,6 +366,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy(t *testing.T) { } func TestAccAWSEFSFileSystem_lifecyclePolicy_update(t *testing.T) { + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -377,22 +375,16 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy_update(t *testing.T) { CheckDestroy: testAccCheckEfsFileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy( - "transition_to_ia", - efs.TransitionToIARulesAfter30Days, - ), + Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy("transition_to_ia", efs.TransitionToIARulesAfter30Days), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, efs.TransitionToIARulesAfter30Days), ), }, { - Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy( - "transition_to_ia", - efs.TransitionToIARulesAfter90Days, - ), + Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy("transition_to_ia", efs.TransitionToIARulesAfter90Days), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, efs.TransitionToIARulesAfter90Days), ), }, @@ -406,6 +398,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy_update(t *testing.T) { } func TestAccAWSEFSFileSystem_lifecyclePolicy_removal(t *testing.T) { + var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -414,19 +407,16 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy_removal(t *testing.T) { CheckDestroy: testAccCheckEfsFileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy( - "transition_to_ia", - efs.TransitionToIARulesAfter14Days, - ), + Config: testAccAWSEFSFileSystemConfigWithLifecyclePolicy("transition_to_ia", efs.TransitionToIARulesAfter14Days), Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, efs.TransitionToIARulesAfter14Days), ), }, { Config: testAccAWSEFSFileSystemConfigRemovedLifecyclePolicy, Check: resource.ComposeTestCheckFunc( - testAccCheckEfsFileSystem(resourceName), + testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemLifecyclePolicy(resourceName, efs.TransitionToIARulesAfter14Days), ), ExpectError: regexp.MustCompile(fmt.Sprintf(`Expected: %s`, efs.TransitionToIARulesAfter14Days)), @@ -451,7 +441,7 @@ func testAccCheckEfsFileSystemDestroy(s *terraform.State) error { FileSystemId: aws.String(rs.Primary.ID), }) if err != nil { - if efsErr, ok := err.(awserr.Error); ok && efsErr.Code() == "FileSystemNotFound" { + if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") { // gone return nil } @@ -465,7 +455,7 @@ func testAccCheckEfsFileSystemDestroy(s *terraform.State) error { return nil } -func testAccCheckEfsFileSystem(resourceID string) resource.TestCheckFunc { +func testAccCheckEfsFileSystem(resourceID string, description *efs.FileSystemDescription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceID] if !ok { @@ -477,11 +467,21 @@ func testAccCheckEfsFileSystem(resourceID string) resource.TestCheckFunc { } conn := testAccProvider.Meta().(*AWSClient).efsconn - _, err := conn.DescribeFileSystems(&efs.DescribeFileSystemsInput{ + fs, err := conn.DescribeFileSystems(&efs.DescribeFileSystemsInput{ FileSystemId: aws.String(rs.Primary.ID), }) - return err + if err != nil { + return err + } + + if fs == nil { + return fmt.Errorf("EFS File System not found") + } + + *fs.FileSystems[0] = *description + + return nil } } @@ -591,6 +591,29 @@ resource "aws_efs_file_system" "test" { } ` +func testAccAWSEFSFileSystemConfigTags1(rName, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_efs_file_system" "test" { + creation_token = %[1]q + tags = { + %[2]q = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccAWSEFSFileSystemConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_efs_file_system" "test" { + creation_token = %[1]q + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +} + func testAccAWSEFSFileSystemConfigPagedTags(rInt int) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { @@ -611,22 +634,11 @@ resource "aws_efs_file_system" "test" { `, rInt) } -func testAccAWSEFSFileSystemConfigWithTags(rInt int) string { +func testAccAWSEFSFileSystemConfigWithMaxTags(rName string) string { return fmt.Sprintf(` resource "aws_efs_file_system" "test" { tags = { - Name = "test-efs-%d" - Another = "tag" - } -} -`, rInt) -} - -func testAccAWSEFSFileSystemConfigWithMaxTags(rInt int) string { - return fmt.Sprintf(` -resource "aws_efs_file_system" "test1" { - tags = { - Name = "test-efs-%d" + Name = %q Another = "tag" Tag00 = "TestTagValue" @@ -679,7 +691,7 @@ resource "aws_efs_file_system" "test1" { Tag47 = "TestTagValue" } } -`, rInt) +`, rName) } const testAccAWSEFSFileSystemConfigWithPerformanceMode = ` From 27aff4d58a21233568b3431fb4be6a87772eadd8 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 18 Jan 2020 09:52:00 +0200 Subject: [PATCH 2/3] refactor tags to use newer functions and drop deprecated ones --- .../keyvaluetags/generators/updatetags/main.go | 6 +----- aws/internal/keyvaluetags/update_tags_gen.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/aws/internal/keyvaluetags/generators/updatetags/main.go b/aws/internal/keyvaluetags/generators/updatetags/main.go index ec6885eddbd..ea62d64f9fb 100644 --- a/aws/internal/keyvaluetags/generators/updatetags/main.go +++ b/aws/internal/keyvaluetags/generators/updatetags/main.go @@ -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": @@ -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": @@ -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": diff --git a/aws/internal/keyvaluetags/update_tags_gen.go b/aws/internal/keyvaluetags/update_tags_gen.go index 29875d261f8..ac10bdebab8 100644 --- a/aws/internal/keyvaluetags/update_tags_gen.go +++ b/aws/internal/keyvaluetags/update_tags_gen.go @@ -1442,12 +1442,12 @@ func EfsUpdateTags(conn *efs.EFS, identifier string, oldTagsMap interface{}, new newTags := New(newTagsMap) if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 { - input := &efs.DeleteTagsInput{ - FileSystemId: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.IgnoreAws().Keys()), + input := &efs.UntagResourceInput{ + ResourceId: aws.String(identifier), + TagKeys: aws.StringSlice(removedTags.IgnoreAws().Keys()), } - _, err := conn.DeleteTags(input) + _, err := conn.UntagResource(input) if err != nil { return fmt.Errorf("error untagging resource (%s): %w", identifier, err) @@ -1455,12 +1455,12 @@ func EfsUpdateTags(conn *efs.EFS, identifier string, oldTagsMap interface{}, new } if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 { - input := &efs.CreateTagsInput{ - FileSystemId: aws.String(identifier), - Tags: updatedTags.IgnoreAws().EfsTags(), + input := &efs.TagResourceInput{ + ResourceId: aws.String(identifier), + Tags: updatedTags.IgnoreAws().EfsTags(), } - _, err := conn.CreateTags(input) + _, err := conn.TagResource(input) if err != nil { return fmt.Errorf("error tagging resource (%s): %w", identifier, err) From 4d97fd5fe9abeed5b15d3e03d84c275dc08ff9f8 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 18 Jan 2020 10:33:12 +0200 Subject: [PATCH 3/3] add disappearing test --- aws/resource_aws_efs_file_system_test.go | 55 ++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 719e5c84162..82d02845ac2 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -87,6 +87,7 @@ func TestResourceAWSEFSFileSystem_hasEmptyFileSystems(t *testing.T) { func TestAccAWSEFSFileSystem_basic(t *testing.T) { var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" + rName := acctest.RandomWithPrefix("tf-acc") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -94,7 +95,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { CheckDestroy: testAccCheckEfsFileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEFSFileSystemConfig, + Config: testAccAWSEFSFileSystemConfig(rName), Check: resource.ComposeTestCheckFunc( testAccMatchResourceAttrRegionalARN(resourceName, "arn", "elasticfilesystem", regexp.MustCompile(`file-system/fs-.+`)), resource.TestCheckResourceAttr(resourceName, "performance_mode", "generalPurpose"), @@ -124,7 +125,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { func TestAccAWSEFSFileSystem_tags(t *testing.T) { var desc efs.FileSystemDescription - rName := acctest.RandomWithPrefix("tf-acc") + rName := acctest.RandomWithPrefix("tf-acc-tags") resourceName := "aws_efs_file_system.test" resource.ParallelTest(t, resource.TestCase{ @@ -430,6 +431,28 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy_removal(t *testing.T) { }) } +func TestAccAWSEFSFileSystem_disappears(t *testing.T) { + var desc efs.FileSystemDescription + resourceName := "aws_efs_file_system.test" + rName := acctest.RandomWithPrefix("tf-acc-disappears") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckEfsFileSystemDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEFSFileSystemConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckEfsFileSystem(resourceName, &desc), + testAccCheckEfsFileSystemDisappears(&desc), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccCheckEfsFileSystemDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).efsconn for _, rs := range s.RootModule().Resources { @@ -455,7 +478,7 @@ func testAccCheckEfsFileSystemDestroy(s *terraform.State) error { return nil } -func testAccCheckEfsFileSystem(resourceID string, description *efs.FileSystemDescription) resource.TestCheckFunc { +func testAccCheckEfsFileSystem(resourceID string, fDesc *efs.FileSystemDescription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceID] if !ok { @@ -475,16 +498,30 @@ func testAccCheckEfsFileSystem(resourceID string, description *efs.FileSystemDes return err } - if fs == nil { + if len(fs.FileSystems) == 0 { return fmt.Errorf("EFS File System not found") } - *fs.FileSystems[0] = *description + *fDesc = *fs.FileSystems[0] return nil } } +func testAccCheckEfsFileSystemDisappears(fDesc *efs.FileSystemDescription) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).efsconn + + input := &efs.DeleteFileSystemInput{ + FileSystemId: fDesc.FileSystemId, + } + + _, err := conn.DeleteFileSystem(input) + + return err + } +} + func testAccCheckEfsCreationToken(resourceID string, expectedToken string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceID] @@ -585,11 +622,13 @@ func testAccCheckEfsFileSystemLifecyclePolicy(resourceID string, expectedVal str } } -const testAccAWSEFSFileSystemConfig = ` +func testAccAWSEFSFileSystemConfig(rName string) string { + return fmt.Sprintf(` resource "aws_efs_file_system" "test" { - creation_token = "radeksimko" + creation_token = %q +} +`, rName) } -` func testAccAWSEFSFileSystemConfigTags1(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(`