Skip to content

Commit 7e139da

Browse files
committed
Fix tests
1 parent 90b130f commit 7e139da

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

internal/service/ec2/transitgateway_route_table_association_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,49 @@ func testAccTransitGatewayRouteTableAssociation_disappears(t *testing.T, semapho
9797
})
9898
}
9999

100+
func testAccTransitGatewayRouteTableAssociation_attachmentChange(t *testing.T, semaphore tfsync.Semaphore) {
101+
if testing.Short() {
102+
t.Skip("skipping long-running test in short mode")
103+
}
104+
105+
ctx := acctest.Context(t)
106+
var v awstypes.TransitGatewayRouteTableAssociation
107+
resourceName := "aws_ec2_transit_gateway_route_table_association.test"
108+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
109+
110+
resource.ParallelTest(t, resource.TestCase{
111+
PreCheck: func() {
112+
testAccPreCheckTransitGatewaySynchronize(t, semaphore)
113+
acctest.PreCheck(ctx, t)
114+
testAccPreCheckTransitGateway(ctx, t)
115+
},
116+
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
117+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
118+
CheckDestroy: testAccCheckTransitGatewayRouteTableAssociationDestroy(ctx),
119+
Steps: []resource.TestStep{
120+
{
121+
Config: testAccTransitGatewayRouteTableAssociationConfig_attachmentChange(rName, 0),
122+
Check: resource.ComposeTestCheckFunc(
123+
testAccCheckTransitGatewayRouteTableAssociationExists(ctx, resourceName, &v),
124+
resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayAttachmentID, "aws_ec2_transit_gateway_vpc_attachment.test.0", names.AttrID),
125+
),
126+
},
127+
{
128+
Config: testAccTransitGatewayRouteTableAssociationConfig_attachmentChange(rName, 1),
129+
Check: resource.ComposeTestCheckFunc(
130+
testAccCheckTransitGatewayRouteTableAssociationExists(ctx, resourceName, &v),
131+
resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayAttachmentID, "aws_ec2_transit_gateway_vpc_attachment.test.1", names.AttrID),
132+
),
133+
ConfigPlanChecks: resource.ConfigPlanChecks{
134+
PreApply: []plancheck.PlanCheck{
135+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionReplace),
136+
},
137+
},
138+
},
139+
},
140+
})
141+
}
142+
100143
func testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation(t *testing.T, semaphore tfsync.Semaphore) {
101144
if testing.Short() {
102145
t.Skip("skipping long-running test in short mode")
@@ -342,3 +385,70 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "test" {
342385
}
343386
`, rName, rBGPASN, strings.Join(allowedPrefixes, `", "`))
344387
}
388+
389+
func testAccTransitGatewayRouteTableAssociationConfig_attachmentChange(rName string, attachmentIndex int) string {
390+
return fmt.Sprintf(`
391+
resource "aws_vpc" "test" {
392+
count = 2
393+
394+
cidr_block = "10.${count.index}.0.0/16"
395+
396+
tags = {
397+
Name = "%[1]s-${count.index}"
398+
}
399+
}
400+
401+
resource "aws_subnet" "test" {
402+
count = 2
403+
404+
vpc_id = aws_vpc.test[count.index].id
405+
cidr_block = "10.${count.index}.0.0/24"
406+
availability_zone = data.aws_availability_zones.available.names[0]
407+
408+
tags = {
409+
Name = "%[1]s-${count.index}"
410+
}
411+
}
412+
413+
data "aws_availability_zones" "available" {
414+
state = "available"
415+
416+
filter {
417+
name = "opt-in-status"
418+
values = ["opt-in-not-required"]
419+
}
420+
}
421+
422+
resource "aws_ec2_transit_gateway" "test" {
423+
tags = {
424+
Name = %[1]q
425+
}
426+
}
427+
428+
resource "aws_ec2_transit_gateway_vpc_attachment" "test" {
429+
count = 2
430+
431+
subnet_ids = [aws_subnet.test[count.index].id]
432+
transit_gateway_default_route_table_association = false
433+
transit_gateway_id = aws_ec2_transit_gateway.test.id
434+
vpc_id = aws_vpc.test[count.index].id
435+
436+
tags = {
437+
Name = "%[1]s-${count.index}"
438+
}
439+
}
440+
441+
resource "aws_ec2_transit_gateway_route_table" "test" {
442+
transit_gateway_id = aws_ec2_transit_gateway.test.id
443+
444+
tags = {
445+
Name = %[1]q
446+
}
447+
}
448+
449+
resource "aws_ec2_transit_gateway_route_table_association" "test" {
450+
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test[%[2]d].id
451+
transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id
452+
}
453+
`, rName, attachmentIndex)
454+
}

internal/service/ec2/transitgateway_route_table_propagation_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,38 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "test" {
301301
}
302302

303303
func testAccTransitGatewayRouteTablePropagationConfig_attachmentChange(rName string, attachmentIndex int) string {
304-
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(`
304+
return fmt.Sprintf(`
305+
resource "aws_vpc" "test" {
306+
count = 2
307+
308+
cidr_block = "10.${count.index}.0.0/16"
309+
310+
tags = {
311+
Name = "%[1]s-${count.index}"
312+
}
313+
}
314+
315+
resource "aws_subnet" "test" {
316+
count = 2
317+
318+
vpc_id = aws_vpc.test[count.index].id
319+
cidr_block = "10.${count.index}.0.0/24"
320+
availability_zone = data.aws_availability_zones.available.names[0]
321+
322+
tags = {
323+
Name = "%[1]s-${count.index}"
324+
}
325+
}
326+
327+
data "aws_availability_zones" "available" {
328+
state = "available"
329+
330+
filter {
331+
name = "opt-in-status"
332+
values = ["opt-in-not-required"]
333+
}
334+
}
335+
305336
resource "aws_ec2_transit_gateway" "test" {
306337
tags = {
307338
Name = %[1]q
@@ -313,7 +344,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" {
313344
314345
subnet_ids = [aws_subnet.test[count.index].id]
315346
transit_gateway_id = aws_ec2_transit_gateway.test.id
316-
vpc_id = aws_vpc.test.id
347+
vpc_id = aws_vpc.test[count.index].id
317348
318349
tags = {
319350
Name = "%[1]s-${count.index}"
@@ -332,5 +363,5 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "test" {
332363
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test[%[2]d].id
333364
transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id
334365
}
335-
`, rName, attachmentIndex))
366+
`, rName, attachmentIndex)
336367
}

internal/service/ec2/transitgateway_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func TestAccTransitGateway_serial(t *testing.T) {
145145
acctest.CtBasic: testAccTransitGatewayRouteTableAssociation_basic,
146146
acctest.CtDisappears: testAccTransitGatewayRouteTableAssociation_disappears,
147147
"replaceExistingAssociation": testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation,
148+
"attachmentChange": testAccTransitGatewayRouteTableAssociation_attachmentChange,
148149
"recreatedDXGateway": testAccTransitGatewayRouteTableAssociation_recreatedDXGateway,
149150
},
150151
"RouteTablePropagation": {

0 commit comments

Comments
 (0)