Skip to content

Commit

Permalink
Merge pull request #40928 from hashicorp/td-testcheckresourceattrset-…
Browse files Browse the repository at this point in the history
…arn-e

testing: Reduce uses of `resource.TestCheckResourceAttrSet` with ARN attributes: `e` services
  • Loading branch information
gdavison authored Jan 15, 2025
2 parents 6fdda48 + 2b8d33d commit 39230db
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 219 deletions.
6 changes: 0 additions & 6 deletions .ci/semgrep/acctest/checks/arn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ rules:
paths:
exclude:
- "internal/service/controltower"
- "internal/service/ec2"
- "internal/service/elasticache"
- "internal/service/elasticbeanstalk"
- "internal/service/elb"
- "internal/service/elbv2"
- "internal/service/events"
- "internal/service/firehose"
- "internal/service/globalaccelerator"
- "internal/service/guardduty"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/ec2_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAccEC2EIP_basic(t *testing.T) {
Config: testAccEIPConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckEIPExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "elastic-ip/{id}"),
resource.TestCheckResourceAttr(resourceName, names.AttrDomain, "vpc"),
resource.TestCheckResourceAttr(resourceName, "ptr_record", ""),
resource.TestCheckResourceAttrSet(resourceName, "public_ip"),
Expand Down
4 changes: 2 additions & 2 deletions internal/service/ec2/ipam_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAccIPAMPool_basic(t *testing.T) {
resource.TestCheckNoResourceAttr(resourceName, "allocation_max_netmask_length"),
resource.TestCheckNoResourceAttr(resourceName, "allocation_min_netmask_length"),
resource.TestCheckResourceAttr(resourceName, "allocation_resource_tags.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrGlobalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "ipam-pool/{id}"),
resource.TestCheckResourceAttr(resourceName, "auto_import", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "aws_service", ""),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
Expand All @@ -66,7 +66,7 @@ func TestAccIPAMPool_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "allocation_min_netmask_length", "32"),
resource.TestCheckResourceAttr(resourceName, "allocation_resource_tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "allocation_resource_tags.test", "1"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrGlobalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "ipam-pool/{id}"),
resource.TestCheckResourceAttr(resourceName, "auto_import", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "aws_service", ""),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test"),
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAccIPAM_basic(t *testing.T) {
Config: testAccIPAMConfig_basic,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIPAMExists(ctx, resourceName, &ipam),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrGlobalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "ipam/{id}"),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
resource.TestCheckResourceAttr(resourceName, "enable_private_gua", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "operating_regions.#", "1"),
Expand Down
22 changes: 12 additions & 10 deletions internal/service/ec2/transitgateway_attachment_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ func testAccTransitGatewayAttachmentDataSource_Filter(t *testing.T, semaphore tf
{
Config: testAccTransitGatewayAttachmentDataSourceConfig_filter(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(resourceName, names.AttrVPCID, dataSourceName, names.AttrResourceID),
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrResourceID, resourceName, names.AttrVPCID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID),
acctest.CheckResourceAttrAccountID(ctx, dataSourceName, "resource_owner_id"),
resource.TestCheckResourceAttr(dataSourceName, names.AttrResourceType, "vpc"),
resource.TestCheckResourceAttrSet(dataSourceName, names.AttrState),
resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsPercent, dataSourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(resourceName, names.AttrID, dataSourceName, names.AttrTransitGatewayAttachmentID),
resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, dataSourceName, names.AttrTransitGatewayID),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayAttachmentID, dataSourceName, names.AttrID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayID, resourceName, names.AttrTransitGatewayID),
acctest.CheckResourceAttrAccountID(ctx, dataSourceName, "transit_gateway_owner_id"),
resource.TestCheckResourceAttr(dataSourceName, "association_state", "associated"),
resource.TestCheckResourceAttrSet(dataSourceName, "association_transit_gateway_route_table_id"),
Expand Down Expand Up @@ -67,14 +68,15 @@ func testAccTransitGatewayAttachmentDataSource_ID(t *testing.T, semaphore tfsync
{
Config: testAccTransitGatewayAttachmentDataSourceConfig_id(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(resourceName, names.AttrVPCID, dataSourceName, names.AttrResourceID),
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrResourceID, resourceName, names.AttrVPCID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID),
acctest.CheckResourceAttrAccountID(ctx, dataSourceName, "resource_owner_id"),
resource.TestCheckResourceAttr(dataSourceName, names.AttrResourceType, "vpc"),
resource.TestCheckResourceAttrSet(dataSourceName, names.AttrState),
resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsPercent, dataSourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(resourceName, names.AttrID, dataSourceName, names.AttrTransitGatewayAttachmentID),
resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, dataSourceName, names.AttrTransitGatewayID),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayAttachmentID, dataSourceName, names.AttrID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayID, resourceName, names.AttrTransitGatewayID),
acctest.CheckResourceAttrAccountID(ctx, dataSourceName, "transit_gateway_owner_id"),
resource.TestCheckResourceAttr(dataSourceName, "association_state", "associated"),
resource.TestCheckResourceAttrSet(dataSourceName, "association_transit_gateway_route_table_id"),
Expand Down
10 changes: 5 additions & 5 deletions internal/service/ec2/vpc_default_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func testAccDefaultSubnet_Existing_basic(t *testing.T) {
Config: testAccVPCDefaultSubnetConfig_basic(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSubnetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "subnet/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_ipv6_address_on_creation", acctest.CtFalse),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"),
Expand Down Expand Up @@ -171,7 +171,7 @@ func testAccDefaultSubnet_Existing_ipv6(t *testing.T) {
Config: testAccVPCDefaultSubnetConfig_ipv6(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSubnetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "subnet/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_ipv6_address_on_creation", acctest.CtTrue),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"),
Expand Down Expand Up @@ -218,7 +218,7 @@ func testAccDefaultSubnet_Existing_privateDNSNameOptionsOnLaunch(t *testing.T) {
Config: testAccVPCDefaultSubnetConfig_privateDNSNameOptionsOnLaunch(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSubnetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "subnet/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_ipv6_address_on_creation", acctest.CtFalse),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"),
Expand Down Expand Up @@ -265,7 +265,7 @@ func testAccDefaultSubnet_NotFound_basic(t *testing.T) {
Config: testAccVPCDefaultSubnetConfig_notFound(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSubnetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "subnet/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_ipv6_address_on_creation", acctest.CtFalse),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"),
Expand Down Expand Up @@ -311,7 +311,7 @@ func testAccDefaultSubnet_NotFound_ipv6Native(t *testing.T) {
Config: testAccVPCDefaultSubnetConfig_ipv6Native(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSubnetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "subnet/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_ipv6_address_on_creation", acctest.CtTrue),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone_id"),
Expand Down
12 changes: 6 additions & 6 deletions internal/service/ec2/vpc_default_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func testAccDefaultVPC_Existing_basic(t *testing.T) {
Config: testAccVPCDefaultVPCConfig_basic,
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down Expand Up @@ -143,7 +143,7 @@ func testAccDefaultVPC_Existing_assignGeneratedIPv6CIDRBlock(t *testing.T) {
Config: testAccVPCDefaultVPCConfig_assignGeneratedIPv6CIDRBlock(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down Expand Up @@ -218,7 +218,7 @@ func testAccDefaultVPC_NotFound_basic(t *testing.T) {
Config: testAccVPCDefaultVPCConfig_basic,
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down Expand Up @@ -265,7 +265,7 @@ func testAccDefaultVPC_NotFound_assignGeneratedIPv6CIDRBlock(t *testing.T) {
Config: testAccVPCDefaultVPCConfig_assignGeneratedIPv6CIDRBlock(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down Expand Up @@ -341,7 +341,7 @@ func testAccDefaultVPC_NotFound_assignGeneratedIPv6CIDRBlockAdoption(t *testing.
Config: testAccVPCDefaultVPCConfig_assignGeneratedIPv6CIDRBlockAdoptionStep1(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down Expand Up @@ -383,7 +383,7 @@ func testAccDefaultVPC_NotFound_assignGeneratedIPv6CIDRBlockAdoption(t *testing.
Config: testAccVPCDefaultVPCConfig_assignGeneratedIPv6CIDRBlockAdoptionStep3(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckVPCExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "vpc/{id}"),
resource.TestCheckResourceAttr(resourceName, "assign_generated_ipv6_cidr_block", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, names.AttrCIDRBlock, "172.31.0.0/16"),
resource.TestCheckResourceAttrSet(resourceName, "default_network_acl_id"),
Expand Down
3 changes: 2 additions & 1 deletion internal/service/ec2/vpc_security_group_egress_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ func TestAccVPCSecurityGroupEgressRule_basic(t *testing.T) {
Config: testAccVPCSecurityGroupEgressRuleConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSecurityGroupEgressRuleExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "security-group-rule/{id}"),
resource.TestCheckResourceAttr(resourceName, "cidr_ipv4", "10.0.0.0/8"),
resource.TestCheckNoResourceAttr(resourceName, "cidr_ipv6"),
resource.TestCheckNoResourceAttr(resourceName, names.AttrDescription),
resource.TestCheckResourceAttr(resourceName, "from_port", "80"),
resource.TestCheckResourceAttrPair(resourceName, names.AttrID, resourceName, "security_group_rule_id"),
resource.TestCheckResourceAttr(resourceName, "ip_protocol", "tcp"),
resource.TestCheckNoResourceAttr(resourceName, "prefix_list_id"),
resource.TestCheckNoResourceAttr(resourceName, "referenced_security_group_id"),
Expand Down
Loading

0 comments on commit 39230db

Please sign in to comment.