As you architect multi-account AWS environments through landing zones, managing network connectivity, security, and observability across dozens or even hundreds of VPCs becomes a critical challenge. Ad-hoc VPC peering rapidly devolves into an unmanageable mesh, hindering scalability and consistent policy enforcement. Centralized networking addresses this by establishing a 'hub' – typically a dedicated network or security VPC – where all ingress/egress traffic from 'spoke' application VPCs is routed. This hub-and-spoke model simplifies routing, enables centralized security inspection, and provides a single, controlled point of entry and exit for your entire cloud estate, drastically reducing operational overhead.
This centralized network hub is also fundamental for efficiently delivering shared services across your organization. Imagine common infrastructure like Active Directory (AD) for identity management, DNS resolvers, centralized logging aggregators, security tools (e.g., IDS/IPS), or proxy servers. Instead of deploying these services redundantly in every application account, or managing a complex web of individual peering connections for each service, they are provisioned once in a dedicated 'shared services' VPC. The centralized networking infrastructure then acts as the secure, high-bandwidth conduit, allowing all application VPCs to access these vital services seamlessly and scalably, without direct exposure or complex route management for every spoke.
AWS Transit Gateway (TGW) is the cornerstone service that enables this advanced, scalable centralized networking architecture. Functioning as a regional virtual router, TGW connects thousands of VPCs and on-premises networks (via VPN or Direct Connect) through a single, central gateway. Instead of creating a 'many-to-many' VPC peering spaghetti, you simply attach all your spoke VPCs—application, shared services, security inspection—to the Transit Gateway. This dramatically simplifies routing tables, provides a single aggregation point for network traffic, allows for flexible routing policies between attachments, and offers inherent high availability and scalability, transforming a fragmented network into a cohesive, manageable, and secure cloud backbone for your enterprise landing zone.
Key Takeaways
- Centralized networking (hub-and-spoke) is crucial for managing network complexity in multi-account cloud environments, preventing VPC peering sprawl.
- AWS Transit Gateway (TGW) is the core service for building this scalable hub-and-spoke architecture, acting as a regional cloud router.
- Shared services (e.g., AD, DNS, logging) reside in a dedicated VPC and are accessed by spoke application VPCs through the centralized network hub (TGW).
- This approach simplifies routing, enables consistent security policy enforcement, and provides a single point for ingress/egress control.
- TGW offers inherent high availability and scalability, crucial for enterprise-grade cloud networks.
Code Example
resource "aws_ec2_transit_gateway" "main_tgw" {
amazon_side_asn = 64512
description = "Main Transit Gateway for landing zone"
tags = {
Name = "prod-main-tgw"
}
}
resource "aws_ec2_transit_gateway_vpc_attachment" "app_vpc_attachment" {
vpc_id = "vpc-0abc123def4567890" # Example: Application VPC ID
transit_gateway_id = aws_ec2_transit_gateway.main_tgw.id
subnet_ids = ["subnet-0123456789abcdef0", "subnet-0fedcba9876543210"] # Subnets for TGW ENIs in App VPC
dns_support = "enable"
ipv6_support = "disable"
transit_gateway_default_route_table_association = true
transit_gateway_default_route_table_propagation = true
tags = {
Name = "app-vpc-attachment-01"
}
}How this code works
This code establishes a centralized network hub, an AWS Transit Gateway, and connects an example application Virtual Private Cloud (VPC) to it. The aws_ec2_transit_gateway resource defines the Transit Gateway itself, giving it a description and an amazon_side_asn for Border Gateway Protocol (BGP) routing, which is a unique identifier within the AWS network. This resource effectively creates the main network "switchboard" for the landing zone, allowing many VPCs and on-premises networks to connect to a single point.
Next, the aws_ec2_transit_gateway_vpc_attachment resource creates the link between a specific vpc_id and the newly created transit_gateway_id. It requires subnet_ids within the attached VPC where the Transit Gateway's network interfaces will reside, enabling traffic flow. A crucial aspect for beginners is transit_gateway_default_route_table_association and transit_gateway_default_route_table_propagation both being set to true. This automatically configures routing by associating the VPC with the Transit Gateway's default route table and propagating its routes. While convenient for initial setup, disabling these for more complex routing requires understanding and managing Transit Gateway route tables manually, which can trip up a beginner expecting continued automatic behavior. Both resources use tags for organizational labeling.