@@ -97,6 +97,49 @@ func testAccTransitGatewayRouteTableAssociation_disappears(t *testing.T, semapho
97
97
})
98
98
}
99
99
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
+
100
143
func testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation (t * testing.T , semaphore tfsync.Semaphore ) {
101
144
if testing .Short () {
102
145
t .Skip ("skipping long-running test in short mode" )
@@ -342,3 +385,70 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "test" {
342
385
}
343
386
` , rName , rBGPASN , strings .Join (allowedPrefixes , `", "` ))
344
387
}
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
+ }
0 commit comments