Production-grade 3-tier infrastructure on Google Cloud, fully automated with Terraform. 54 resources across 7 modules.
The Problem
Architecture
Infrastructure as Code
VPC, subnets, firewall, Cloud Router, NAT, Private Services Access
Service accounts with least-privilege role bindings
Instance templates, MIGs, health checks, autoscalers
Cloud SQL PostgreSQL, private IP, automated backups
GCS bucket + IAM bindings
Secret Manager entries + access bindings
Global LB, backend services, URL routing, CDN
Production Patterns
Public and private subnets with strict firewall rules between tiers
Private Services Access for managed services -- the tricky part
No default compute service account. Custom SAs with minimal roles.
Secret Manager for credentials. Not env vars, not config files.
Layered security: firewall rules + Cloud Armor WAF at the edge
Preemptible instances, autoscaling, right-sized e2-micro VMs
Tools
Hard-Won Gotchas
Public subnet still needs NAT -- instances have no external IPs; all traffic routes through the load balancer. Outbound requires Cloud NAT.
Private Services Access requires /16 CIDR + VPC peering -- the most confusing part of Cloud SQL private networking. Needs a reserved IP range and explicit peering connection.
5 resources = 1 load balancer -- GCP LB is verbose: forwarding rule, target proxy, URL map, backend service, health check. Each one a separate Terraform resource.
Cloud Armor quota = 0 on free trial -- you need to request a quota increase or use a billing account. Discovered this at deploy time.
Interactive setup.sh for guided deployment -- built a shell script that walks through project setup, API enablement, and terraform apply in ~15 minutes.
By The Numbers
A production-grade landing zone you can deploy in 15 minutes, tear down in seconds, and fork for any GCP project.
Production-grade Terraform infrastructure on Google Cloud.