Referencing to AWS Direct connect gateway TGW attachment using terraform


I am using terraform(aws provider 5.8.0) to create and associate a route table to a direct connect gateway TGW association. The terraform resource block for “aws_ec2_transit_gateway_route_table_association” requires a “transit_gateway_attachment_id”. How do I reference to the TGW attachment to direct connect gateway in this case? I can’t seem to find any attribute for “aws_dx_gateway_association” resource that provides a “transit_gateway_attachment_id”.

Below is a sample code I am using. The last resource block for “aws_ec2_transit_gateway_route_table_association” is where I am having trouble finding a way to reference to the TGW attachment to the direct connect gateway.

resource “aws_dx_gateway_association” “dxg-to-tgw-assoc”{
dx_gateway_id = some dxg id
associated_gateway_id = some tgw id

allowed_prefixes = [

#Create route table
resource “aws_ec2_transit_gateway_route_table” “rt-A” {
transit_gateway_id =

#Create routes
resource “aws_ec2_transit_gateway_route” “some-routes” {
destination_cidr_block = “A.B.C.D/24”
transit_gateway_attachment_id = some vpc attachment id
transit_gateway_route_table_id =

#Associate route table to TGW attachments
#Associate to DXGW association
resource “aws_ec2_transit_gateway_route_table_association” “assoc-rt-A-to-dxg-attachment” {
transit_gateway_attachment_id = <how do I reference to the dxg transit gw association?>
transit_gateway_route_table_id =

Thank you.


Anyone have any ideas?

Hi @halphyr , from dx_gateway_association doc I can see, attribute dx_gateway_association_id .

So, can you try :

resource “aws_ec2_transit_gateway_route_table_association” “foobar” {
transit_gateway_attachment_id = aws_dx_gateway_association.dxg-to-tgw-assoc.dx_gateway_association_id
transit_gateway_route_table_id =

or I see just id as attribute as well, so you can also try :

resource “aws_ec2_transit_gateway_route_table_association” “foobar” {
transit_gateway_attachment_id =
transit_gateway_route_table_id =

Hi @tanmay-bhat,

I wasn’t sure that the dx_gateway_association_id or id attribute you mentioned was the same as the EC2 Transit Gateway Attachment identifier expected from the transit_gateway_attachment_id arguement for ec2_transit_gateway_route resource. Thats why I posed the question here.

I will confirm this once I have my Telco Direct Connect established and DXG and TGW associated. Thanks!