From 95a646464792b4ae66e6c9c9f31b439c7688e1b8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 31 Jul 2023 15:31:07 -0400 Subject: [PATCH 1/8] Add 'testAccTransitGatewayRouteTableAssociationConfig_base'. --- ...sitgateway_route_table_association_test.go | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/internal/service/ec2/transitgateway_route_table_association_test.go b/internal/service/ec2/transitgateway_route_table_association_test.go index e1ddac46cbb..4187d4f7056 100644 --- a/internal/service/ec2/transitgateway_route_table_association_test.go +++ b/internal/service/ec2/transitgateway_route_table_association_test.go @@ -177,7 +177,7 @@ func testAccCheckTransitGatewayRouteTableAssociationDestroy(ctx context.Context) } } -func testAccTransitGatewayRouteTableAssociationConfig_basic(rName string) string { +func testAccTransitGatewayRouteTableAssociationConfig_base(rName string) string { return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { @@ -185,19 +185,25 @@ resource "aws_ec2_transit_gateway" "test" { } } -resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = aws_subnet.test[*].id - transit_gateway_default_route_table_association = false - transit_gateway_id = aws_ec2_transit_gateway.test.id - vpc_id = aws_vpc.test.id + +resource "aws_ec2_transit_gateway_route_table" "test" { + transit_gateway_id = aws_ec2_transit_gateway.test.id tags = { Name = %[1]q } } -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id +`, rName)) +} + +func testAccTransitGatewayRouteTableAssociationConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationConfig_base(rName), fmt.Sprintf(` +resource "aws_ec2_transit_gateway_vpc_attachment" "test" { + subnet_ids = aws_subnet.test[*].id + transit_gateway_default_route_table_association = false + transit_gateway_id = aws_ec2_transit_gateway.test.id + vpc_id = aws_vpc.test.id tags = { Name = %[1]q @@ -212,13 +218,7 @@ resource "aws_ec2_transit_gateway_route_table_association" "test" { } func testAccTransitGatewayRouteTableAssociationConfig_replaceExistingAssociation(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - + return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { subnet_ids = aws_subnet.test[*].id transit_gateway_default_route_table_association = true @@ -230,14 +230,6 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { } } -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id - - tags = { - Name = %[1]q - } -} - resource "aws_ec2_transit_gateway_route_table_association" "test" { transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id From a3b7572b8a37738b481a0cba2b90ea9a6bdfbfe1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 31 Jul 2023 16:39:01 -0400 Subject: [PATCH 2/8] r/aws_ec2_transit_gateway_vpc_attachment: Simplify acceptance test configurations. --- .../ec2/transitgateway_vpc_attachment_test.go | 159 +++--------------- 1 file changed, 21 insertions(+), 138 deletions(-) diff --git a/internal/service/ec2/transitgateway_vpc_attachment_test.go b/internal/service/ec2/transitgateway_vpc_attachment_test.go index 62911fc1dc6..93adb36512d 100644 --- a/internal/service/ec2/transitgateway_vpc_attachment_test.go +++ b/internal/service/ec2/transitgateway_vpc_attachment_test.go @@ -235,7 +235,7 @@ func testAccTransitGatewayVPCAttachment_SubnetIDs(t *testing.T) { CheckDestroy: testAccCheckTransitGatewayVPCAttachmentDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccTransitGatewayVPCAttachmentConfig_subnetIds2(rName), + Config: testAccTransitGatewayVPCAttachmentConfig_subnetIDs2(rName), Check: resource.ComposeTestCheckFunc( testAccCheckTransitGatewayVPCAttachmentExists(ctx, resourceName, &transitGatewayVpcAttachment1), resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "2"), @@ -247,7 +247,7 @@ func testAccTransitGatewayVPCAttachment_SubnetIDs(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccTransitGatewayVPCAttachmentConfig_subnetIds1(rName), + Config: testAccTransitGatewayVPCAttachmentConfig_subnetIDs1(rName), Check: resource.ComposeTestCheckFunc( testAccCheckTransitGatewayVPCAttachmentExists(ctx, resourceName, &transitGatewayVpcAttachment2), testAccCheckTransitGatewayVPCAttachmentNotRecreated(&transitGatewayVpcAttachment1, &transitGatewayVpcAttachment2), @@ -255,7 +255,7 @@ func testAccTransitGatewayVPCAttachment_SubnetIDs(t *testing.T) { ), }, { - Config: testAccTransitGatewayVPCAttachmentConfig_subnetIds2(rName), + Config: testAccTransitGatewayVPCAttachmentConfig_subnetIDs2(rName), Check: resource.ComposeTestCheckFunc( testAccCheckTransitGatewayVPCAttachmentExists(ctx, resourceName, &transitGatewayVpcAttachment3), testAccCheckTransitGatewayVPCAttachmentNotRecreated(&transitGatewayVpcAttachment2, &transitGatewayVpcAttachment3), @@ -514,25 +514,7 @@ func testAccCheckTransitGatewayVPCAttachmentNotRecreated(i, j *ec2.TransitGatewa } func testAccTransitGatewayVPCAttachmentConfig_base(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { Name = %[1]q @@ -544,7 +526,7 @@ resource "aws_ec2_transit_gateway" "test" { func testAccTransitGatewayVPCAttachmentConfig_basic(rName string) string { return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), ` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id } @@ -555,7 +537,7 @@ func testAccTransitGatewayVPCAttachmentConfig_applianceModeSupport(rName, appMod return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { appliance_mode_support = %[2]q - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -570,7 +552,7 @@ func testAccTransitGatewayVPCAttachmentConfig_dnsSupport(rName, dnsSupport strin return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { dns_support = %[2]q - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -582,27 +564,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { } func testAccTransitGatewayVPCAttachmentConfig_ipv6Support(rName, ipv6Support string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - assign_generated_ipv6_cidr_block = true - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 8, 1) - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnetsIPv6(rName, 1), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { Name = %[1]q @@ -611,7 +573,7 @@ resource "aws_ec2_transit_gateway" "test" { resource "aws_ec2_transit_gateway_vpc_attachment" "test" { ipv6_support = %[2]q - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -623,10 +585,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { } func testAccTransitGatewayVPCAttachmentConfig_sharedTransitGateway(rName string) string { - return acctest.ConfigCompose( - acctest.ConfigAlternateAccountProvider(), - acctest.ConfigAvailableAZsNoOptInDefaultExclude(), - fmt.Sprintf(` + return acctest.ConfigCompose(acctest.ConfigAlternateAccountProvider(), acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` data "aws_organizations_organization" "test" {} resource "aws_ec2_transit_gateway" "test" { @@ -657,28 +616,10 @@ resource "aws_ram_principal_association" "test" { resource_share_arn = aws_ram_resource_share.test.id } -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - resource "aws_ec2_transit_gateway_vpc_attachment" "test" { depends_on = [aws_ram_principal_association.test, aws_ram_resource_association.test] - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -689,28 +630,8 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { `, rName)) } -func testAccTransitGatewayVPCAttachmentConfig_subnetIds1(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - count = 2 - - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "10.0.${count.index}.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - +func testAccTransitGatewayVPCAttachmentConfig_subnetIDs1(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { Name = %[1]q @@ -729,28 +650,8 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { `, rName)) } -func testAccTransitGatewayVPCAttachmentConfig_subnetIds2(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - count = 2 - - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "10.0.${count.index}.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - +func testAccTransitGatewayVPCAttachmentConfig_subnetIDs2(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { Name = %[1]q @@ -772,7 +673,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { func testAccTransitGatewayVPCAttachmentConfig_tags1(rName, tagKey1, tagValue1 string) string { return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -786,7 +687,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { func testAccTransitGatewayVPCAttachmentConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -799,25 +700,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { } func testAccTransitGatewayVPCAttachmentConfig_defaultRouteTableAssociationAndPropagationDisabled(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { default_route_table_association = "disable" default_route_table_propagation = "disable" @@ -828,7 +711,7 @@ resource "aws_ec2_transit_gateway" "test" { } resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_default_route_table_association = false transit_gateway_default_route_table_propagation = false transit_gateway_id = aws_ec2_transit_gateway.test.id @@ -844,7 +727,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { func testAccTransitGatewayVPCAttachmentConfig_defaultRouteTableAssociation(rName string, transitGatewayDefaultRouteTableAssociation bool) string { return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_default_route_table_association = %[2]t transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -859,7 +742,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { func testAccTransitGatewayVPCAttachmentConfig_defaultRouteTablePropagation(rName string, transitGatewayDefaultRouteTablePropagation bool) string { return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_default_route_table_propagation = %[2]t transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id From bc77a17013a332b3eb3be6f57215068a29c8e319 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 31 Jul 2023 16:42:28 -0400 Subject: [PATCH 3/8] d/aws_ec2_transit_gateway_vpc_attachment: Simplify acceptance test configurations. --- ...gateway_vpc_attachment_data_source_test.go | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/internal/service/ec2/transitgateway_vpc_attachment_data_source_test.go b/internal/service/ec2/transitgateway_vpc_attachment_data_source_test.go index ac68d1879c6..90645df320d 100644 --- a/internal/service/ec2/transitgateway_vpc_attachment_data_source_test.go +++ b/internal/service/ec2/transitgateway_vpc_attachment_data_source_test.go @@ -117,33 +117,9 @@ data "aws_ec2_transit_gateway_vpc_attachment" "test" { } func testAccTransitGatewayVPCAttachmentDataSourceConfig_id(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - + return acctest.ConfigCompose(testAccTransitGatewayVPCAttachmentConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id From 941b895116520f27d208922bd24a2de34088ade3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 1 Aug 2023 08:50:49 -0400 Subject: [PATCH 4/8] Additional checks in 'testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation'. --- .../service/ec2/transitgateway_route_table_association_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/ec2/transitgateway_route_table_association_test.go b/internal/service/ec2/transitgateway_route_table_association_test.go index 4187d4f7056..e5a2fe1b7fe 100644 --- a/internal/service/ec2/transitgateway_route_table_association_test.go +++ b/internal/service/ec2/transitgateway_route_table_association_test.go @@ -100,6 +100,8 @@ func testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation(t *te resource.TestCheckResourceAttrSet(resourceName, "resource_type"), resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_attachment_id", transitGatewayVpcAttachmentResourceName, "id"), resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_route_table_id", transitGatewayRouteTableResourceName, "id"), + resource.TestCheckResourceAttr(transitGatewayVpcAttachmentResourceName, "transit_gateway_default_route_table_association", "true"), + resource.TestCheckResourceAttr(transitGatewayVpcAttachmentResourceName, "transit_gateway_default_route_table_propagation", "true"), ), // aws_ec2_transit_gateway_vpc_attachment.test.transit_gateway_default_route_table_association shows diff: ExpectNonEmptyPlan: true, @@ -193,7 +195,6 @@ resource "aws_ec2_transit_gateway_route_table" "test" { Name = %[1]q } } - `, rName)) } From 6f080d8d766c0dc5d012f5032ae1c8f7d0e14e11 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Aug 2023 09:29:39 -0400 Subject: [PATCH 5/8] Add CHANGELOG entry. --- .changelog/#####.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..68936682bfc --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ec2_transit_gateway_vpc_attachment: Change `transit_gateway_default_route_table_association` and `transit_gateway_default_route_table_propagation` to Computed +``` \ No newline at end of file From f53e9412276530b2d11fb18c7fa9655c03a6d328 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Aug 2023 09:55:22 -0400 Subject: [PATCH 6/8] r/aws_ec2_transit_gateway_vpc_attachment: Change 'transit_gateway_default_route_table_association' and 'transit_gateway_default_route_table_propagation' to Computed. --- .../ec2/transitgateway_vpc_attachment.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/service/ec2/transitgateway_vpc_attachment.go b/internal/service/ec2/transitgateway_vpc_attachment.go index b1d0a085403..2adba22f3fd 100644 --- a/internal/service/ec2/transitgateway_vpc_attachment.go +++ b/internal/service/ec2/transitgateway_vpc_attachment.go @@ -67,12 +67,12 @@ func ResourceTransitGatewayVPCAttachment() *schema.Resource { "transit_gateway_default_route_table_association": { Type: schema.TypeBool, Optional: true, - Default: true, + Computed: true, }, "transit_gateway_default_route_table_propagation": { Type: schema.TypeBool, Optional: true, - Default: true, + Computed: true, }, "transit_gateway_id": { Type: schema.TypeString, @@ -132,11 +132,22 @@ func resourceTransitGatewayVPCAttachmentCreate(ctx context.Context, d *schema.Re // We cannot modify Transit Gateway Route Tables for Resource Access Manager shared Transit Gateways. if aws.StringValue(transitGateway.OwnerId) == aws.StringValue(output.TransitGatewayVpcAttachment.VpcOwnerId) { - if err := transitGatewayRouteTableAssociationUpdate(ctx, conn, aws.StringValue(transitGateway.Options.AssociationDefaultRouteTableId), d.Id(), d.Get("transit_gateway_default_route_table_association").(bool)); err != nil { + // Default values of transit_gateway_default_route_table_association and transit_gateway_default_route_table_propagation are both 'true'. + transitGatewayDefaultRouteTableAssociation := true + if v := d.GetRawConfig().GetAttr("transit_gateway_default_route_table_association"); v.IsKnown() && !v.IsNull() { + transitGatewayDefaultRouteTableAssociation = v.True() + } + + if err := transitGatewayRouteTableAssociationUpdate(ctx, conn, aws.StringValue(transitGateway.Options.AssociationDefaultRouteTableId), d.Id(), transitGatewayDefaultRouteTableAssociation); err != nil { return sdkdiag.AppendErrorf(diags, "creating EC2 Transit Gateway VPC Attachment: %s", err) } - if err := transitGatewayRouteTablePropagationUpdate(ctx, conn, aws.StringValue(transitGateway.Options.PropagationDefaultRouteTableId), d.Id(), d.Get("transit_gateway_default_route_table_propagation").(bool)); err != nil { + transitGatewayDefaultRouteTablePropagation := true + if v := d.GetRawConfig().GetAttr("transit_gateway_default_route_table_propagation"); v.IsKnown() && !v.IsNull() { + transitGatewayDefaultRouteTablePropagation = v.True() + } + + if err := transitGatewayRouteTablePropagationUpdate(ctx, conn, aws.StringValue(transitGateway.Options.PropagationDefaultRouteTableId), d.Id(), transitGatewayDefaultRouteTablePropagation); err != nil { return sdkdiag.AppendErrorf(diags, "creating EC2 Transit Gateway VPC Attachment: %s", err) } } From 5630c534a91856364f0b26a4f137327ae847d556 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Aug 2023 11:14:47 -0400 Subject: [PATCH 7/8] transitgateway: Simplify some acceptance test configurations. --- ...sitgateway_route_table_association_test.go | 9 +-- ...ute_table_associations_data_source_test.go | 59 +++------------- ...sitgateway_route_table_propagation_test.go | 29 +++----- ...ute_table_propagations_data_source_test.go | 67 ++----------------- 4 files changed, 24 insertions(+), 140 deletions(-) diff --git a/internal/service/ec2/transitgateway_route_table_association_test.go b/internal/service/ec2/transitgateway_route_table_association_test.go index e5a2fe1b7fe..1315e8a08da 100644 --- a/internal/service/ec2/transitgateway_route_table_association_test.go +++ b/internal/service/ec2/transitgateway_route_table_association_test.go @@ -103,8 +103,6 @@ func testAccTransitGatewayRouteTableAssociation_replaceExistingAssociation(t *te resource.TestCheckResourceAttr(transitGatewayVpcAttachmentResourceName, "transit_gateway_default_route_table_association", "true"), resource.TestCheckResourceAttr(transitGatewayVpcAttachmentResourceName, "transit_gateway_default_route_table_propagation", "true"), ), - // aws_ec2_transit_gateway_vpc_attachment.test.transit_gateway_default_route_table_association shows diff: - ExpectNonEmptyPlan: true, }, { ResourceName: resourceName, @@ -221,10 +219,9 @@ resource "aws_ec2_transit_gateway_route_table_association" "test" { func testAccTransitGatewayRouteTableAssociationConfig_replaceExistingAssociation(rName string) string { return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = aws_subnet.test[*].id - transit_gateway_default_route_table_association = true - transit_gateway_id = aws_ec2_transit_gateway.test.id - vpc_id = aws_vpc.test.id + subnet_ids = aws_subnet.test[*].id + transit_gateway_id = aws_ec2_transit_gateway.test.id + vpc_id = aws_vpc.test.id tags = { Name = %[1]q diff --git a/internal/service/ec2/transitgateway_route_table_associations_data_source_test.go b/internal/service/ec2/transitgateway_route_table_associations_data_source_test.go index efa8c46d6a0..9bd94bb90ef 100644 --- a/internal/service/ec2/transitgateway_route_table_associations_data_source_test.go +++ b/internal/service/ec2/transitgateway_route_table_associations_data_source_test.go @@ -53,14 +53,8 @@ func testAccTransitGatewayRouteTableAssociationsDataSource_filter(t *testing.T) }) } -func testAccTransitGatewayRouteTableAssociationsDataSourceConfig_basic(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - +func testAccTransitGatewayRouteTableAssociationsDataSourceConfig_base(rName string) string { + return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationConfig_base(rName), fmt.Sprintf(` resource "aws_ec2_transit_gateway_vpc_attachment" "test" { subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id @@ -73,60 +67,25 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" { } } -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id - - tags = { - Name = %[1]q - } -} - resource "aws_ec2_transit_gateway_route_table_association" "test" { transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id } +`, rName)) +} +func testAccTransitGatewayRouteTableAssociationsDataSourceConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationsDataSourceConfig_base(rName), ` data "aws_ec2_transit_gateway_route_table_associations" "test" { transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id depends_on = [aws_ec2_transit_gateway_route_table_association.test] } -`, rName)) +`) } func testAccTransitGatewayRouteTableAssociationsDataSourceConfig_filter(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = aws_subnet.test[*].id - transit_gateway_id = aws_ec2_transit_gateway.test.id - vpc_id = aws_vpc.test.id - - transit_gateway_default_route_table_association = false - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table_association" "test" { - transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id - transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id -} - + return acctest.ConfigCompose(testAccTransitGatewayRouteTableAssociationsDataSourceConfig_base(rName), ` data "aws_ec2_transit_gateway_route_table_associations" "test" { transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id @@ -137,5 +96,5 @@ data "aws_ec2_transit_gateway_route_table_associations" "test" { depends_on = [aws_ec2_transit_gateway_route_table_association.test] } -`, rName)) +`) } diff --git a/internal/service/ec2/transitgateway_route_table_propagation_test.go b/internal/service/ec2/transitgateway_route_table_propagation_test.go index d76473d86c0..2ad09f41d84 100644 --- a/internal/service/ec2/transitgateway_route_table_propagation_test.go +++ b/internal/service/ec2/transitgateway_route_table_propagation_test.go @@ -138,25 +138,8 @@ func testAccCheckTransitGatewayRouteTablePropagationDestroy(ctx context.Context) } } -func testAccTransitGatewayRouteTablePropagationConfig_basic(rName string) string { - return fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - +func testAccTransitGatewayRouteTablePropagationConfig_base(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_ec2_transit_gateway" "test" { tags = { Name = %[1]q @@ -164,7 +147,7 @@ resource "aws_ec2_transit_gateway" "test" { } resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = [aws_subnet.test.id] + subnet_ids = aws_subnet.test[*].id transit_gateway_id = aws_ec2_transit_gateway.test.id vpc_id = aws_vpc.test.id @@ -180,10 +163,14 @@ resource "aws_ec2_transit_gateway_route_table" "test" { Name = %[1]q } } +`, rName)) +} +func testAccTransitGatewayRouteTablePropagationConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccTransitGatewayRouteTablePropagationConfig_base(rName), ` resource "aws_ec2_transit_gateway_route_table_propagation" "test" { transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id } -`, rName) +`) } diff --git a/internal/service/ec2/transitgateway_route_table_propagations_data_source_test.go b/internal/service/ec2/transitgateway_route_table_propagations_data_source_test.go index 57346ab4b0a..5f3b415c301 100644 --- a/internal/service/ec2/transitgateway_route_table_propagations_data_source_test.go +++ b/internal/service/ec2/transitgateway_route_table_propagations_data_source_test.go @@ -4,7 +4,6 @@ package ec2_test import ( - "fmt" "testing" "github.com/aws/aws-sdk-go/service/ec2" @@ -54,75 +53,17 @@ func testAccTransitGatewayRouteTablePropagationsDataSource_filter(t *testing.T) } func testAccTransitGatewayRouteTablePropagationsDataSourceConfig_basic(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = aws_subnet.test[*].id - transit_gateway_id = aws_ec2_transit_gateway.test.id - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table_propagation" "test" { - transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id - transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id -} - + return acctest.ConfigCompose(testAccTransitGatewayRouteTablePropagationConfig_basic(rName), ` data "aws_ec2_transit_gateway_route_table_propagations" "test" { transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id depends_on = [aws_ec2_transit_gateway_route_table_propagation.test] } -`, rName)) +`) } func testAccTransitGatewayRouteTablePropagationsDataSourceConfig_filter(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` -resource "aws_ec2_transit_gateway" "test" { - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_vpc_attachment" "test" { - subnet_ids = aws_subnet.test[*].id - transit_gateway_id = aws_ec2_transit_gateway.test.id - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table" "test" { - transit_gateway_id = aws_ec2_transit_gateway.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_ec2_transit_gateway_route_table_propagation" "test" { - transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.test.id - transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id -} - + return acctest.ConfigCompose(testAccTransitGatewayRouteTablePropagationConfig_basic(rName), ` data "aws_ec2_transit_gateway_route_table_propagations" "test" { transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.test.id @@ -133,5 +74,5 @@ data "aws_ec2_transit_gateway_route_table_propagations" "test" { depends_on = [aws_ec2_transit_gateway_route_table_propagation.test] } -`, rName)) +`) } From 5313bfce99ad03ffb2c97387c178420c7e5c9c8c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 2 Aug 2023 13:04:43 -0400 Subject: [PATCH 8/8] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 32821.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 32821.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/32821.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/32821.txt