DEV Community

Cover image for How to attach VPCs to a TGW with Terraform?
Augusto Valdivia for AWS Community Builders

Posted on • Updated on

How to attach VPCs to a TGW with Terraform?

As your startup company keeps growing faster than ever before and adopting the full range of cloud solutions it is time to build bigger.

After carefully reviewing the current accounts strategy and looking into future strategies the company has determined how to design the new networking configuration of their growing applications.

In order to adapt to the growing pressures, the company should consider the following:

  • Avoid complex infrastructure
  • Consider high scalability to meet extreme demand
  • Expand availability to a global scale
  • Implement inter region connectivity
  • Leverage Hybrid Architecture

As you finish reading these requirements you should have a good idea as to which AWS resource is most suitable for this infrastructure. If you were thinking about Transit Gateway, you are heading in the right direction. We will be discussing the reasons behind this approach throughout this article and conclude with building the design using Terraform. Vamos!

Diagram 1: AWS-TGW:
Alt Text

What is AWS Transit Gateway (TGW)?

A TGW is a virtual router (hub) that allows customer VPC’s to interconnect with on premise networks using a single gateway.

Let us review some of the great features that AWS-TGW offers:

  • Scales up to 5,000 VPCs
  • Supports 10,000 routes in each route table
  • Uses hub & spoke topology
  • Scales horizontally
  • Integrates with IAM
  • Connects Maximum Transmission Unit (MTU) of 8500 bytes between VPCs, AWS Direct Connect, Transit Gateway Connect and Peering attachment. 1500 bytes over VPN.

Let us review AWS-TGW infrastructure architecture requirements:

  • Needs to be attached to one or more VPCs
  • Requires at least one subnet per AZ
  • Requires one route table association with TGW

Note - TGW does not support routing between VPC’s with overlapping CIDR-block


TGW implementation solves the complexities of implementing hybrid architecture design. As we can see TGW provides control over the network requirements and would satisfy the company’s growing demand.

Terraform: Templates-previews

Alt Text

Now it is time to get hands on building this infrastructure.

Find the Terraform repo and instructions for this project here

more information here

Functions, arguments and expressions of Terraform that were used in the above project:

types and values

Top comments (0)