Using Transit Gateways on AWS for Network Optimization
?? **Elevating Network Infrastructure with Transit Gateways: A Terraform Success Story**
Our team at GMS (gmobility.com) is thrilled to share a recent triumph where we collaborated with a client to revamp their network infrastructure using Terraform. One of the key highlights of this transformation was the introduction of transit gateways, which replaced the previous VPN tunnels connecting to each VPC. This strategic shift brought significant benefits in terms of network management, scalability, and security. Let’s dive into the details! ??
Here is a similar example of how the network architecture looked before the transit gateway implementation:
**The Challenge:**
**The Solution:**
Below is a high level example of how we configured our terraform code to include transit gateway configuration including connecting the customer gateway to the network hub.
provider "aws" {
region = "us-west-2" # Replace with your desired AWS region
}
resource "aws_ec2_transit_gateway" "network_hub" {
description = "Network Hub Transit Gateway"
}
# Network Hub (Account A) - Customer Gateway Connection
resource "aws_ec2_transit_gateway_vpn_attachment" "vpn_attachment" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpn_gateway_id = "your_customer_gateway_id" # Replace with the ID of your Customer Gateway
transit_gateway_default_route_table_association = true
transit_gateway_default_route_table_propagation = true
}
# Network Hub (Account A) -> Workspaces (Account B) Connection
resource "aws_ram_resource_share" "share_account_b" {
name = "Transit Gateway Share - Workspaces (Account B)"
allow_external_principals = true
}
resource "aws_ram_principal_association" "associate_account_b" {
resource_share_arn = aws_ram_resource_share.share_account_b.arn
principal = "account_b_id" # Replace with the ID of Workspaces (Account B)
}
resource "aws_ram_resource_association" "associate_transit_gateway_b" {
resource_share_arn = aws_ram_resource_share.share_account_b.arn
resource_arn = aws_ec2_transit_gateway.network_hub.arn
}
# Network Hub (Account A) -> New App Non Prod (Account C) Connection
resource "aws_ram_resource_share" "share_account_c" {
name = "Transit Gateway Share - New App Non Prod (Account C)"
allow_external_principals = true
}
resource "aws_ram_principal_association" "associate_account_c" {
resource_share_arn = aws_ram_resource_share.share_account_c.arn
principal = "account_c_id" # Replace with the ID of New App Non Prod (Account C)
}
resource "aws_ram_resource_association" "associate_transit_gateway_c" {
resource_share_arn = aws_ram_resource_share.share_account_c.arn
resource_arn = aws_ec2_transit_gateway.network_hub.arn
}
# Network Hub (Account A) -> New App Prod (Account D) Connection
resource "aws_ram_resource_share" "share_account_d" {
name = "Transit Gateway Share - New App Prod (Account D)"
allow_external_principals = true
}
resource "aws_ram_principal_association" "associate_account_d" {
resource_share_arn = aws_ram_resource_share.share_account_d.arn
principal = "account_d_id" # Replace with the ID of New App Prod (Account D)
}
resource "aws_ram_resource_association" "associate_transit_gateway_d" {
resource_share_arn = aws_ram_resource_share.share_account_d.arn
resource_arn = aws_ec2_transit_gateway.network_hub.arn
}
# Workspaces (Account B) VPCs
resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment_b1" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpc_id = "vpc_b1_id" # Replace with the ID of Workspaces (Account B)'s VPC 1
subnet_ids = ["subnet_b1_id"] # Replace with the IDs of Workspaces (Account B)'s VPC 1 subnets
}
resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment_b2" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpc_id = "vpc_b2_id" # Replace with the ID of Workspaces (Account B)'s VPC 2
subnet_ids = ["subnet_b2_id"] # Replace with the IDs of Workspaces (Account B)'s VPC 2 subnets
}
# New App Non Prod (Account C) VPCs
resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment_c1" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpc_id = "vpc_c1_id" # Replace with the ID of New App Non Prod (Account C)'s VPC 1
subnet_ids = ["subnet_c1_id"] # Replace with the IDs of New App Non Prod (Account C)'s VPC 1 subnets
}
resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment_c2" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpc_id = "vpc_c2_id" # Replace with the ID of New App Non Prod (Account C)'s VPC 2
subnet_ids = ["subnet_c2_id"] # Replace with the IDs of New App Non Prod (Account C)'s VPC 2 subnets
}
# New App Prod (Account D) VPC
resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment_d" {
transit_gateway_id = aws_ec2_transit_gateway.network_hub.id
vpc_id = "vpc_d_id" # Replace with the ID of New App Prod (Account D)'s VPC
subnet_ids = ["subnet_d_id"] # Replace with the IDs of New App Prod (Account D)'s VPC subnets
}
**The Benefits of Transit Gateways:**
? **Simplified Network Management:** The introduction of transit gateways reduced the complexity of network management by consolidating network traffic routing and eliminating the need for individual VPN connections to each VPC.
? **Enhanced Scalability:** With transit gateways, the client gained the ability to easily add new VPCs without the hassle of setting up additional VPN tunnels. This streamlined expansion ensured their network infrastructure could scale effortlessly as their business grew.
? **Improved Security and Control:** Transit gateways offered granular control over network traffic flow, enabling the client to implement consistent security policies and manage access to resources across all VPCs from a centralized location.
? **Simplified Connectivity:** The deployment of transit gateways simplified connectivity between VPCs, eliminating the need for complex and error-prone VPN configurations. This resulted in improved network performance and reduced latency.
? **Cost Optimization:** By replacing multiple VPN tunnels with a single transit gateway, the client achieved cost savings by reducing the licensing, maintenance, and operational expenses associated with managing numerous VPN connections.
Through our Terraform-powered approach, we seamlessly incorporated transit gateways into the client’s network infrastructure. By leveraging infrastructure-as-code principles, we ensured that the deployment of transit gateways was consistent, repeatable, and easily auditable.
This transformative shift to transit gateways and the use of Terraform allowed us to orchestrate this change efficiently, empowering the client to optimize network management, enhance scalability, and fortify their security posture.
Join us on this journey of network transformation and leverage the power of transit gateways to unlock the full potential of your network infrastructure.
Check out our website at?www.gmobility.com.?We provide AWS Cloud & DevOps solutions to enhance your infrastructure.
#GMS #NetworkInfrastructure #Terraform #TransitGateways #NetworkManagement #Scalability #Security #Innovation