Sub topic 5
Attaching VPCs to a transit gateway
This chapter assumes you know CIDR blocks, subnets, route tables, and the AWS CLI. It also assumes you have read the previous chapter on the transit gateway as a regional router.
What an attachment is
An attachment is the link between a transit gateway and another network. A VPC attachment connects one VPC to the transit gateway. Other attachment types include VPN, Direct Connect gateway, and peering. This chapter covers VPC attachments.
When you create a VPC attachment, you choose one subnet per Availability Zone (AZ). AWS places a network interface in each chosen subnet. Traffic from that AZ enters the transit gateway through that interface.
Create the transit gateway
The commands below create a transit gateway with default association and propagation turned off. That choice makes routing explicit. You decide which attachment uses which route table, rather than letting AWS put everything in one default table.
aws ec2 create-transit-gateway \
--description "hub" \
--options AmazonSideAsn=64512,DefaultRouteTableAssociation=disable,DefaultRouteTablePropagation=disable
aws ec2 create-transit-gateway-vpc-attachment \
--transit-gateway-id tgw-0123456789abcdef0 \
--vpc-id vpc-0aaa1111bbb22222c \
--subnet-ids subnet-0aaa1111 subnet-0bbb2222AmazonSideAsn is the private autonomous system number the transit gateway uses for BGP sessions. It matters mainly when you add VPN or Direct Connect later. The two subnet IDs here must be in different AZs of the same VPC.
Attachment lifecycle
A new attachment starts in the pending state and moves to available when it is ready. If the VPC and the transit gateway are in different accounts, the attachment waits in pendingAcceptance. The transit gateway owner must accept it.
Check the state with:
aws ec2 describe-transit-gateway-vpc-attachments \
--transit-gateway-attachment-ids tgw-attach-0123456789abcdef0 \
--query "TransitGatewayVpcAttachments[0].State"Share the transit gateway across accounts with AWS Resource Access Manager (RAM) before the other account can create an attachment.
Common errors
- One subnet per AZ only. You cannot select two subnets in the same AZ for one attachment. The call fails.
- Dedicated subnets help. Many teams create a small subnet in each AZ just for attachments. Security groups do not apply to these interfaces, but network ACLs on the attachment subnets do apply, so a dedicated subnet keeps those rules simple.
- Attached does not mean routable. An available attachment carries no traffic until it is associated with a transit gateway route table and the VPC route tables point at the transit gateway. Those steps are the next chapters.
- Overlapping CIDRs. Two attached VPCs with the same CIDR cannot both be reached by route. A later chapter covers workarounds.
- Adding AZs later. If you add a subnet in a new AZ, modify the attachment to include it. Otherwise that AZ stays unreachable.
Exercise
You created a VPC attachment using subnets in AZ a and AZ b. The VPC also has workloads in AZ c, and a VPC route sends 10.1.0.0/16 to the transit gateway. Instances in AZ c cannot reach the other VPC. What is the likely cause and the fix?
Show answer
The attachment has no subnet in AZ c, so traffic from that AZ has no transit gateway network interface to enter through. Add a subnet from AZ c to the attachment with modify-transit-gateway-vpc-attachment and --add-subnet-ids.