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

Replace custom single-attribute ImportStateIdFuncs with acctest.AttrImportStateIdFunc #39898

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
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
Loading