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 it to associate the VPN gateway attachment to the non-default table. But when I run the above code it adds it to 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 name tag to default route table that is not working as well.
Use the resource “aws_route_table” rather than “aws_default_route_table”
vs.
I tried this:
resource “aws_route_table” “default” {
transit_gateway_id = “${aws_ec2_transit_gateway.tgw.id}”
tags = {
Name = "HelloWorld"
}
}
Its not working. Getting following errors:
Error: aws_route_table.default: “vpc_id”: required field is not set
Error: aws_route_table.default: : invalid or unknown key: transit_gateway_id
Also main question was how can I update custom route table instead of default. If I am not able to change name of default that is not a big issue.
Hi,
For the resource aws_ec2_transit_gateway
there are a few options
-
default_route_table_association
- (Optional) Whether resource attachments are automatically associated with the default association route table. Valid values: disable
, enable
. Default value: enable
.
-
default_route_table_propagation
- (Optional) Whether resource attachments automatically propagate routes to the default propagation route table. Valid values: disable
, enable
. Default value: enable
.
Problem is these options cannot be applied to the route table itself. You can only apply this option to the transit gateway which does not help with the situation??
Was this problem resolved?
It’s not really a problem, it just works like that.
When automatic association/propagation is activated on the transit gateway, every VPC that are attached to the TGW are also implicitly attached to the default route table and their routes are propagated inside.
If you need to attach exceptionaly a VPC to a specific route table, you first need to manually delete (I think that Terraform cannot do that) its association with the default route table.
Another solution is to deactivate automatic association/propagation on your TGW and manage these things on your own with Terraform for each attachment.