Skip to content

Commit

Permalink
Merge pull request #39898 from hashicorp/td-attr-importstateidfunc
Browse files Browse the repository at this point in the history
Replace custom single-attribute `ImportStateIdFunc`s with `acctest.AttrImportStateIdFunc`
  • Loading branch information
gdavison authored Oct 28, 2024
2 parents 0446658 + 72102d8 commit 34dc6e4
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 329 deletions.
13 changes: 1 addition & 12 deletions internal/service/chatbot/slack_channel_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testAccSlackChannelConfiguration_basic(t *testing.T) {
{
ResourceName: testResourceSlackChannelConfiguration,
ImportState: true,
ImportStateIdFunc: testAccSlackChannelConfigurationImportStateIDFunc(testResourceSlackChannelConfiguration),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(testResourceSlackChannelConfiguration, "chat_configuration_arn"),
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: "chat_configuration_arn",
},
Expand Down Expand Up @@ -177,17 +177,6 @@ func testAccPreCheck(ctx context.Context, t *testing.T) {
}
}

func testAccSlackChannelConfigurationImportStateIDFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not found: %s", resourceName)
}

return rs.Primary.Attributes["chat_configuration_arn"], nil
}
}

func testAccSlackChannelConfigurationConfig_basic(rName, channelID, teamID string) string {
return fmt.Sprintf(`
data "aws_iam_policy_document" "assume_role" {
Expand Down
27 changes: 8 additions & 19 deletions internal/service/ec2/vpc_default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestAccVPCDefaultRouteTable_basic(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
},
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestAccVPCDefaultRouteTable_Route_mode(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
{
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestAccVPCDefaultRouteTable_swap(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToTransitGateway(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
},
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToVPCEndpoint(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
// Default route tables do not currently have a method to remove routes during deletion.
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestAccVPCDefaultRouteTable_vpcEndpointAssociation(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
},
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestAccVPCDefaultRouteTable_conditionalCIDRBlock(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
},
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestAccVPCDefaultRouteTable_prefixListToInternetGateway(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportStateVerify: true,
},
// Default route tables do not currently have a method to remove routes during deletion.
Expand Down Expand Up @@ -558,17 +558,6 @@ func testAccCheckDefaultRouteTableDestroy(ctx context.Context) resource.TestChec
}
}

func testAccDefaultRouteTableImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not found: %s", resourceName)
}

return rs.Primary.Attributes[names.AttrVPCID], nil
}
}

func testAccVPCDefaultRouteTableConfig_id(defaultRouteTableId string) string {
return fmt.Sprintf(`
resource "aws_default_route_table" "test" {
Expand Down
15 changes: 2 additions & 13 deletions internal/service/ec2/vpc_dhcp_options_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAccVPCDHCPOptionsAssociation_basic(t *testing.T) {
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccVPCDHCPOptionsAssociationVPCImportIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportState: true,
ImportStateVerify: true,
},
Expand Down Expand Up @@ -133,25 +133,14 @@ func TestAccVPCDHCPOptionsAssociation_default(t *testing.T) {
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccVPCDHCPOptionsAssociationVPCImportIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCID),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccVPCDHCPOptionsAssociationVPCImportIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not found: %s", resourceName)
}

return rs.Primary.Attributes[names.AttrVPCID], nil
}
}

func testAccCheckVPCDHCPOptionsAssociationDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx)
Expand Down
15 changes: 2 additions & 13 deletions internal/service/ec2/vpc_endpoint_private_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAccVPCEndpointPrivateDNS_basic(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccVPCEndpointPrivateDNSImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCEndpointID),
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: names.AttrVPCEndpointID,
},
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestAccVPCEndpointPrivateDNS_disabled(t *testing.T) {
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccVPCEndpointPrivateDNSImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, names.AttrVPCEndpointID),
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: names.AttrVPCEndpointID,
},
Expand Down Expand Up @@ -230,17 +230,6 @@ func testAccCheckVPCEndpointPrivateDNSDisabled(ctx context.Context, n string) re
}
}

func testAccVPCEndpointPrivateDNSImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not found: %s", resourceName)
}

return rs.Primary.Attributes[names.AttrVPCEndpointID], nil
}
}

func testAccVPCEndpointPrivateDNSConfig_basic(rName string, enabled bool) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
Expand Down
Loading

0 comments on commit 34dc6e4

Please sign in to comment.