diff --git a/internal/service/efs/file_system_data_source_test.go b/internal/service/efs/file_system_data_source_test.go index 1cc80384316..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"), @@ -60,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"), @@ -92,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"), @@ -123,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"), ), @@ -157,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 44ff769f441..d2c4f7d6715 100644 --- a/internal/service/efs/file_system_test.go +++ b/internal/service/efs/file_system_test.go @@ -39,7 +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"), - acctest.MatchResourceAttrAccountID(resourceName, "name"), + resource.TestCheckResourceAttr(resourceName, "name", ""), resource.TestCheckResourceAttr(resourceName, "number_of_mount_targets", "0"), acctest.MatchResourceAttrAccountID(resourceName, "owner_id"), resource.TestCheckResourceAttr(resourceName, "performance_mode", "generalPurpose"), @@ -219,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), ), }, { @@ -572,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) }