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

r/aws_ec2_transit_gateway_vpc_attachment: transit_gateway_default_route_table_association is Computed #32821

3 changes: 3 additions & 0 deletions .changelog/32821.txt
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ 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,
},
{
ResourceName: resourceName,
Expand Down Expand Up @@ -177,24 +177,14 @@ 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 = {
Name = %[1]q
}
}

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
}
}

resource "aws_ec2_transit_gateway_route_table" "test" {
transit_gateway_id = aws_ec2_transit_gateway.test.id
Expand All @@ -203,25 +193,14 @@ resource "aws_ec2_transit_gateway_route_table" "test" {
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 testAccTransitGatewayRouteTableAssociationConfig_replaceExistingAssociation(rName string) string {
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(`
resource "aws_ec2_transit_gateway" "test" {
tags = {
Name = %[1]q
}
}

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 = true
transit_gateway_default_route_table_association = false
transit_gateway_id = aws_ec2_transit_gateway.test.id
vpc_id = aws_vpc.test.id

Expand All @@ -230,8 +209,19 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" {
}
}

resource "aws_ec2_transit_gateway_route_table" "test" {
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 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_id = aws_ec2_transit_gateway.test.id
vpc_id = aws_vpc.test.id

tags = {
Name = %[1]q
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -137,5 +96,5 @@ data "aws_ec2_transit_gateway_route_table_associations" "test" {

depends_on = [aws_ec2_transit_gateway_route_table_association.test]
}
`, rName))
`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,16 @@ 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
}
}

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

Expand All @@ -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)
`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package ec2_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -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

Expand All @@ -133,5 +74,5 @@ data "aws_ec2_transit_gateway_route_table_propagations" "test" {

depends_on = [aws_ec2_transit_gateway_route_table_propagation.test]
}
`, rName))
`)
}
19 changes: 15 additions & 4 deletions internal/service/ec2/transitgateway_vpc_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down
Loading