How to attach VPCs to a TGW with Terraform?
Tags: aws, terraform, awstgw, awsvpc
Published: 2021-05-25 21:51:34

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rjcjfosf43f0gxu9igxj.png)

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

**Conclusion**

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1oq0ksfawfiayewbqpi.png)

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

[Find the Terraform repo and instructions for this project here](https://github.com/ValAug/AWS_TGW_VPC-s)

**more information here**

- [Transit-gateway official AWS documentation](https://aws.amazon.com/transit-gateway/?whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc)

- [what is Transit Gateway?](https://docs.aws.amazon.com/vpc/latest/tgw/what-is-transit-gateway.html)

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

[providers](https://www.terraform.io/docs/language/providers/index.html)
[variables](https://www.terraform.io/docs/language/values/index.html)
[modules](https://www.terraform.io/docs/language/modules/index.html)
[resources](https://www.terraform.io/docs/language/resources/index.html)
[types and values](https://www.terraform.io/docs/language/expressions/types.html)