NoviceMe
NoviceMe

Reputation: 3256

Update custom transit gateway route table instead of default - terraform

I have the following code:

resource "aws_ec2_transit_gateway_route_table" "non_default" {
 transit_gateway_id = "${aws_ec2_transit_gateway.tgw.id}"
}

resource "aws_ec2_transit_gateway_route_table_association" "non_default_association" {
  transit_gateway_attachment_id  = "${aws_vpn_connection.tgw-vpn-attachment.transit_gateway_attachment_id}"
  transit_gateway_route_table_id = "${aws_ec2_transit_gateway_route_table.non_default.id}"

  depends_on = ["aws_vpn_connection.tgw-vpn-attachment"]
}

# Name default route table — This is not working either.
resource "aws_default_route_table" "default" {
  default_route_table_id = "${aws_ec2_transit_gateway.tgw.id}"

  tags = {
    Name = "HelloWorld"
  }
}

I want to associate the VPN gateway attachment to the non-default route table. But when I run the above code it adds it to the default route table? I need a default route table and don’t want to disable it. How can I achieve the above results?

Also when I try to add a name tag to the default route table that is not working as well.

Upvotes: 2

Views: 2429

Answers (1)

Vikyol
Vikyol

Reputation: 5645

You can change the default propagation route table for an attachment. Make sure that you follow all the steps below.

  1. Create a Transit Gateway (TGW).
  2. Create a TGW attachment.
  3. Create a TGW route table.
  4. Associate the route table with the TGW attachment (ec2:TransitGatewayRouteTableAssociation).
  5. Enable route propagation for the route table (ec2:TransitGatewayRouteTablePropagation).

After you enable propagation, the routes should appear in the specified route table instead of the default one.

aws_ec2_transit_gateway_route_table_propagation

Enables the specified attachment to propagate routes to the specified propagation route table.

resource "aws_ec2_transit_gateway_route_table_association" "association" {
  transit_gateway_attachment_id  = "${aws_vpn_connection.tgw-vpn-attachment.transit_gateway_attachment_id}"
  transit_gateway_route_table_id = "${aws_ec2_transit_gateway_route_table.non_default.id}"
}

resource "aws_ec2_transit_gateway_route_table_propagation" "propagation" {
    transit_gateway_attachment_id  = "${aws_vpn_connection.tgw-vpn-attachment.transit_gateway_attachment_id}"
    transit_gateway_route_table_id = "${aws_ec2_transit_gateway_route_table.non_default.id}"
}

Upvotes: 1

Related Questions