Phase 6: Cloud Deployment in Client Environments · 55 min · Python · AWS · GCP
VPC Configuration & Network Isolation
Your AI system lives inside their network. Configure it properly.
What you will learn
- Configure VPCs: subnets, route tables, internet gateways, NAT gateways, VPC peering
- Set up security groups and network ACLs with least-privilege inbound/outbound rules
- Deploy AI workloads in private subnets: no public IPs, NAT for outbound-only access
- Connect client VPCs with deployment VPCs: peering, Transit Gateway
- Navigate cloud provider differences: AWS VPC vs. GCP VPC vs. Azure VNet
Objective
What you'll learn
This lesson takes approximately 55 min. By the end, you will be able to:
- Configure VPCs: subnets, route tables, internet gateways, NAT gateways, VPC peering
- Set up security groups and network ACLs with least-privilege inbound/outbound rules
- Deploy AI workloads in private subnets: no public IPs, NAT for outbound-only access
- Connect client VPCs with deployment VPCs: peering, Transit Gateway
- Navigate cloud provider differences: AWS VPC vs. GCP VPC vs. Azure VNet
The Problem
When you deploy AI systems inside a client's cloud environment, you're deploying into their VPC. You need to understand VPC architecture: subnets, route tables, security groups, NAT gateways, VPC peering, and network ACLs. Your network configuration determines whether the system can reach the model API, access databases, and comply with security policies.
The Concept
VPC architecture for AI workloads
# Terraform: VPC with public and private subnets for AI deployment
# Architecture:
# Public subnet — NAT gateway, bastion host (if needed)
# Private subnet — AI workloads (EKS nodes, ECS tasks, EC2)
# No public IPs on AI workloads — outbound via NAT gateway
resource "aws_vpc" "ai_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "ai-deployment-vpc"
Environment = "production"
ManagedBy = "terraform"
}
}
# Public subnet (for NAT gateway only)
resource "aws_subnet" "public" {
vpc_id = aws_vpc.ai_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
tags = { Name = "ai-public-subnet", Tier = "public" }
}
# Private subnet (AI workloads — no internet ingress)
resource "aws_subnet" "private" {
vpc_id = aws_vpc.ai_vpc.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1a"
tags = { Name = "ai-private-subnet", Tier = "private" }
}
# Internet gateway for public subnet
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.ai_vpc.id
}
# NAT gateway for private subnet outbound traffic
resource "aws_eip" "nat" {
domain = "vpc"
}
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public.id # NAT must be in public subnet
tags = { Name = "ai-nat-gateway" }
}
# Route table for private subnet — route outbound via NAT
resource "aws_route_table" "private" {
vpc_id = aws_vpc.ai_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat.id
}
tags = { Name = "ai-private-rt" }
}
resource "aws_route_table_association" "private" {
subnet_id = aws_subnet.private.id
route_table_id = aws_route_table.private.id
}
# Route table for public subnet — route outbound via IGW
resource "aws_route_table" "public" {
vpc_id = aws_vpc.ai_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = { Name = "ai-public-rt" }
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
}
Security groups: least-privilege for AI workloads
# Security group for AI workloads — least privilege
resource "aws_security_group" "ai_workload" {
name = "ai-workload-sg"
description = "Security group for AI workloads in private subnet"
vpc_id = aws_vpc.ai_vpc.id
# No inbound from internet — only from internal ALB
ingress {
description = "HTTP from internal ALB"
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [aws_security_group.internal_alb.id]
}
# Outbound: only to specific APIs (model providers, databases)
egress {
description = "HTTPS to model API (OpenAI/Anthropic)"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # In production: restrict to provider IP ranges
}
egress {
description = "Postgres to RDS"
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.rds.id]
}
# No other egress — deny by default
tags = { Name = "ai-workload-sg" }
}
# Internal ALB security group — accepts traffic from client VPC only
resource "aws_security_group" "internal_alb" {
name = "internal-alb-sg"
vpc_id = aws_vpc.ai_vpc.id
ingress {
description = "HTTPS from client VPC"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["10.1.0.0/16"] # Client VPC CIDR
}
egress {
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [aws_security_group.ai_workload.id]
}
}
Network ACLs: subnet-level defense
# Network ACL for private subnet — stateless filtering at subnet boundary
resource "aws_network_acl" "private" {
vpc_id = aws_vpc.ai_vpc.id
subnet_ids = [aws_subnet.private.id]
# Allow inbound from VPC only
ingress {
rule_no = 100
action = "allow"
protocol = "-1"
cidr_block = "10.0.0.0/16" # VPC CIDR
from_port = 0
to_port = 0
}
# Deny all other inbound (implicit deny, but explicit for documentation)
ingress {
rule_no = 200
action = "deny"
protocol = "-1"
cidr_block = "0.0.0.0/0"
from_port = 0
to_port = 0
}
# Allow all outbound (NAT handles filtering)
egress {
rule_no = 100
action = "allow"
protocol = "-1"
cidr_block = "0.0.0.0/0"
from_port = 0
to_port = 0
}
tags = { Name = "ai-private-nacl" }
}
VPC peering: client VPC to deployment VPC
# VPC peering connection between client VPC and AI deployment VPC
resource "aws_vpc_peering_connection" "client_to_ai" {
vpc_id = aws_vpc.ai_vpc.id # AI deployment VPC
peer_vpc_id = var.client_vpc_id # Client's existing VPC
peer_owner_id = var.client_account_id # Different AWS account
peer_region = var.client_region
auto_accept = false # Client must accept from their side
accepter {
allow_remote_vpc_dns_resolution = true
}
requester {
allow_remote_vpc_dns_resolution = true
}
tags = { Name = "client-to-ai-peering" }
}
# Route table update: route client VPC traffic via peering connection
resource "aws_route" "to_client_vpc" {
route_table_id = aws_route_table.private.id
destination_cidr_block = var.client_vpc_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.client_to_ai.id
}
Transit gateway for multi-VPC architecture
# Transit Gateway — for clients with multiple VPCs that need to connect to AI
resource "aws_ec2_transit_gateway" "tgw" {
description = "Transit gateway for AI deployment connectivity"
default_route_table_association = "enable"
default_route_table_propagation = "enable"
tags = { Name = "ai-tgw" }
}
# Attach AI VPC to Transit Gateway
resource "aws_ec2_transit_gateway_vpc_attachment" "ai_vpc" {
transit_gateway_id = aws_ec2_transit_gateway.tgw.id
vpc_id = aws_vpc.ai_vpc.id
subnet_ids = [aws_subnet.private.id]
tags = { Name = "ai-vpc-tgw-attachment" }
}
# Attach client VPC to Transit Gateway (client does this on their side)
# resource "aws_ec2_transit_gateway_vpc_attachment" "client_vpc" { ... }
Cloud provider differences
AWS VPC vs GCP VPC vs Azure VNet — key differences for FDEs:
- Subnet model
- AWS: Regional subnets — each subnet is AZ-specific. Must create subnet per AZ for HA.
- GCP: Regional subnets — subnets span all zones in a region automatically.
- Azure: VNet subnets are regional — similar to GCP, subnets span all AZs.
- Default rules
- AWS: Security groups default deny all inbound, allow all outbound.
- GCP: Firewall rules default deny all inbound, deny all outbound (must explicitly allow).
- Azure: NSG default allow all inbound and outbound (must restrict manually).
- Nat gateway
- AWS: NAT Gateway (managed, charged per hour + per GB). No NAT instances needed.
- GCP: Cloud NAT (managed, charged per GB only). No NAT gateway needed per AZ.
- Azure: NAT Gateway (managed) or Azure Firewall SNAT. Must explicitly configure.
- Peering
- AWS: VPC Peering — 1:1 only. For many-to-many, use Transit Gateway.
- GCP: VPC Peering — supports transitive peering via Network Connectivity Center.
- Azure: VNet Peering — supports transitive peering via Azure Virtual WAN.
- Private access
- AWS: VPC Endpoints (PrivateLink) for AWS services without internet.
- GCP: Private Google Access for Google APIs without external IPs.
- Azure: Private Endpoints (Private Link) for Azure PaaS services.
Build
Practical application
In the lab, you'll write Terraform to create a VPC with public/private subnets and a NAT gateway, configure security groups with least-privilege rules for AI workloads, set up network ACLs at the subnet boundary, establish VPC peering between a client VPC and your deployment VPC, and deploy an AI service in a private subnet with no public IP.
Before you write Terraform, it helps to sanity-check a subnet plan on paper. The tool below validates a simple CIDR allocation for overlaps and capacity.
# Validate that proposed subnets fit inside a VPC CIDR without overlapping
import ipaddress
def check_subnet_plan(vpc_cidr, subnets):
vpc = ipaddress.ip_network(vpc_cidr)
parsed = []
for name, cidr in subnets.items():
net = ipaddress.ip_network(cidr)
if not net.subnet_of(vpc):
print(f"FAIL: {name} ({cidr}) is not inside VPC {vpc_cidr}")
continue
parsed.append((name, net))
for i in range(len(parsed)):
for j in range(i + 1, len(parsed)):
name_a, net_a = parsed[i]
name_b, net_b = parsed[j]
if net_a.overlaps(net_b):
print(f"FAIL: {name_a} overlaps with {name_b}")
print(f"VPC {vpc_cidr}: {vpc.num_addresses} addresses total")
for name, net in parsed:
print(f" {name}: {str(net):>14} -> {net.num_addresses} addresses")
plan = {
"public": "10.0.1.0/24",
"private": "10.0.2.0/24",
}
check_subnet_plan("10.0.0.0/16", plan)
Your AI service is deployed in a private subnet with a NAT gateway. The service needs to call OpenAI's API and connect to an RDS Postgres instance. The security group on the AI workload allows all outbound traffic (0.0.0.0/0 on all ports). The client's security team rejected this configuration. What's the fix?
The client's security team correctly identified that allowing all outbound traffic on all ports violates least-privilege principles. The fix is to replace the broad egress rule with specific rules: (1) port 443 to 0.0.0.0/0 for HTTPS calls to OpenAI/Anthropic APIs (can be further restricted to provider IP ranges), (2) port 5432 to the RDS security group for database access. Security groups are stateful (return traffic is automatically allowed), so you don't need inbound rules for responses. NACLs are stateless and operate at the subnet boundary — they complement but don't replace security groups. Moving to a public subnet would make the security posture worse. Removing all outbound rules would break the service entirely.
This lesson is free
You've read the first 4 sections. The rest covers Key Terms & Next. A free account opens all of it, with its practice questions and its lab. No card.
Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card.
Browse all courses · View pricing · DeVenture Academy