Sub topic 8
Isolating environments with separate route tables
This chapter assumes you can create a transit gateway, attach VPCs, and read a route table, as covered in the earlier chapters. Here you will use several transit gateway route tables to keep production and development apart while both reach a shared services VPC.
Why one route table is not enough
If you leave default association and propagation turned on, every attachment lands in one default route table. Every VPC then learns every other VPC's CIDR, so any VPC can reach any other. That is rarely what you want between production and development.
Two settings control the isolation:
- Association decides which route table an attachment uses when it sends traffic into the transit gateway. Each attachment is associated with exactly one table.
- Propagation decides which route tables learn the attachment's CIDR. One attachment can propagate into many tables.
To isolate environments, give each its own table and be selective about propagation.
A three-table design
Suppose you have a prod VPC (10.0.0.0/16), a dev VPC (10.1.0.0/16), and a shared services VPC (10.9.0.0/16). The shared services VPC holds DNS and tooling.
The rules in each table follow from this:
| Route table | Associated attachment | Learns routes from | Can reach |
|---|---|---|---|
| Prod | Prod | Shared | Shared only |
| Dev | Dev | Shared | Shared only |
| Shared | Shared | Prod, Dev | Prod and Dev |
Prod traffic is looked up in the prod table. That table has no dev route, so prod cannot reach dev.
Configuring it
The transit gateway must have been created with DefaultRouteTableAssociation=disable and DefaultRouteTablePropagation=disable. Otherwise new attachments join the default table automatically. The commands below show the prod table. Repeat the pattern for dev and shared.
aws ec2 create-transit-gateway-route-table \
--transit-gateway-id tgw-0123456789abcdef0
# Prod traffic uses the prod table
aws ec2 associate-transit-gateway-route-table \
--transit-gateway-route-table-id tgw-rtb-0prod00000000000 \
--transit-gateway-attachment-id tgw-attach-0prod0000000000
# The shared VPC's CIDR appears in the prod table
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0prod00000000000 \
--transit-gateway-attachment-id tgw-attach-0shared00000000
# The prod VPC's CIDR appears in the shared table
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0shared0000000000 \
--transit-gateway-attachment-id tgw-attach-0prod0000000000Making the isolation explicit
Missing routes already block traffic. You can also add a static blackhole route, which drops matching traffic and documents your intent. A static route also takes precedence over a propagated route for the same CIDR.
aws ec2 create-transit-gateway-route \
--destination-cidr-block 10.1.0.0/16 \
--transit-gateway-route-table-id tgw-rtb-0prod00000000000 \
--blackholeCommon errors
- Default association left on. New attachments join the default table and may see everything. Disable it at creation.
- One-way propagation. If the shared table does not learn the prod CIDR, return traffic has nowhere to go. Traffic from prod reaches shared, but replies are dropped.
- Forgotten VPC routes. The transit gateway tables only matter if each VPC subnet route table also points the remote CIDR at the transit gateway.
- Wrong association. An attachment can have only one association. Changing it means disassociating first.
Exercise
Prod can reach shared services, but replies never arrive. Prod's table has a route to 10.9.0.0/16. Which table is most likely missing a route, and how do you fix it?
Show answer
The shared services table is missing the prod CIDR (10.0.0.0/16). Replies from shared are looked up in the table associated with the shared attachment. Enable propagation of the prod attachment into the shared table, or add a static route for 10.0.0.0/16 pointing at the prod attachment.