Overview
We provide 6 production-ready Terraform modules for deploying complete GCP infrastructure with best practices built-in. These modules enable infrastructure-as-code deployments with high availability, security, and cost optimization.6 Modules
VPC, GKE, Cloud SQL, Redis, Workload Identity, Backend
3 Environments
Dev, Staging, Production configurations
9,000+ Lines
Production-grade infrastructure code
Module Architecture
Quick Start
1. Setup Terraform Backend
This creates a GCS bucket for Terraform state with versioning, encryption, and logging.
See Backend Setup Guide for details.
2. Deploy Environment
- Production
- Staging
- Development
Module Reference
1. GCP VPC Module
Location:terraform/modules/gcp-vpc/
Creates VPC network optimized for GKE with:
- VPC-native networking (secondary IP ranges for pods/services)
- Cloud NAT with dynamic port allocation
- Cloud Router with BGP
- Firewall rules (internal, IAP SSH, health checks)
- Private Service Connection for Cloud SQL/Memorystore
- VPC Flow Logs with sampling
- Optional Cloud Armor for DDoS protection
Complete VPC Module Documentation
1,088-line README with examples, best practices, and troubleshooting
2. GKE Autopilot Module
Location:terraform/modules/gke-autopilot/
Creates fully managed GKE Autopilot cluster with:
- Regional or zonal deployment
- Workload Identity enabled by default
- Binary Authorization support
- GKE Security Posture Dashboard
- Dataplane V2 (eBPF networking)
- Network Policy enforcement
- Managed Prometheus
- Automated backups (GKE Backup)
- Fleet registration (Anthos)
- Pay-per-pod pricing: 40-60% cost savings vs. Standard GKE
- Fully managed: Google handles nodes, upgrades, scaling
- Security hardened: CIS benchmark compliance out-of-box
- Auto-scaling: VPA, HPA, cluster autoscaler included
Complete GKE Module Documentation
900-line README with Autopilot vs. Standard comparison, best practices, examples
3. Cloud SQL PostgreSQL Module
Location:terraform/modules/cloudsql/
Creates highly available PostgreSQL database with:
- Regional HA with automatic failover
- Automated backups + point-in-time recovery (PITR)
- Read replicas (cross-region support)
- Query Insights (Performance Insights)
- Private IP only (VPC integration)
- Customer-managed encryption (CMEK) support
- Pre-configured monitoring alerts
4. Memorystore Redis Module
Location:terraform/modules/memorystore/
Creates highly available Redis cache with:
- STANDARD_HA tier with automatic failover
- Read replicas (up to 5)
- RDB or AOF persistence
- TLS encryption in transit
- Redis AUTH password authentication
- Cross-region replicas for DR
5. Workload Identity Module
Location:terraform/modules/gke-workload-identity/
Creates IAM bindings for Kubernetes pods to use GCP service accounts securely (no credential files needed).
- Replaces service account key files (more secure)
- Pod-level IAM permissions
- Resource-specific access control
- Auto-generated Kubernetes SA manifests
6. Backend Setup Module
Location:terraform/backend-setup-gcp/
Creates GCS bucket for Terraform state management with:
- Versioning enabled (10 versions retained)
- Access logging to separate bucket
- Encryption at rest
- Lifecycle policies
- Public access prevention
Module Composition Example
Here’s how modules work together in a complete environment:Environment Configurations
Development (Cost-Optimized)
Location:terraform/environments/gcp-dev/
Configuration
- Cluster: Zonal (single zone)
- Cloud SQL: db-custom-1-3840, no HA
- Redis: 1 GB BASIC tier
- NAT: Auto-allocated IPs
- Flow Logs: 10% sampling
Cost
$100-150/month50% cheaper than staging
Staging (Production-Like)
Location:terraform/environments/gcp-staging/
Configuration
- Cluster: Regional (3 zones)
- Cloud SQL: db-custom-2-7680, HA
- Redis: 3 GB STANDARD_HA
- NAT: Auto-allocated IPs
- Monitoring: Full alerts
Cost
$250-350/monthProduction-like for pre-release testing
Production (Enterprise-Grade)
Location:terraform/environments/gcp-prod/
Configuration
- Cluster: Regional (3 zones), deletion protection
- Cloud SQL: db-custom-4-15360, HA + read replica
- Redis: 5 GB STANDARD_HA + replicas
- NAT: 2 static IPs (whitelisting)
- Binary Auth: Ready to enable
- Backups: Daily (30-day retention)
Cost
$880-1,275/monthEnterprise HA with full observabilityWith 3-year CUD: $466/month (66% savings)
High Availability Features
High Availability Features
- 99.95% SLA from GKE regional cluster
- Automatic failover for Cloud SQL (2-3 min RTO)
- Automatic failover for Redis (1-2 min RTO)
- 3 pod replicas minimum (Pod Disruption Budget)
- Topology spread across zones
- Automated backups with 7-day PITR
Module Features
Variable Validation
All modules include comprehensive input validation:Detailed Outputs
Every module exports useful outputs for module composition:Built-in Monitoring
Modules include pre-configured Cloud Monitoring alerts:- GKE: Cluster upgrade available, high CPU
- Cloud SQL: High CPU/memory/disk usage
- Redis: High memory, high connections, instance down
Security by Default
All modules implement security best practices:- Private IPs only (no public access)
- Encryption at rest and in transit
- Customer-managed encryption key (CMEK) support
- Network policies and firewall rules
- Workload Identity integration
Best Practices
1. Use Modules, Don’t Fork
2. Pin Module Versions
For stability, consider pinning to specific versions:3. Use terraform.tfvars for Secrets
Never commit sensitive values to Git:4. Remote State for Teams
Use GCS backend for collaboration:5. Module Dependencies
Usedepends_on when modules have dependencies:
Common Tasks
View Outputs
Update Infrastructure
Import Existing Resources
Destroy Environment
Troubleshooting
Error: Quota Exceeded
Error: Quota Exceeded
Issue: GCP project quota limits exceededSolution:Common quotas to increase:
- CPUs: 100+
- In-use IP addresses: 50+
- Persistent disk SSD: 1000 GB+
Error: API Not Enabled
Error: API Not Enabled
Issue: Required API not enabledSolution:
State Lock Errors
State Lock Errors
Issue: Terraform state lockedSolution:
GCS provides automatic state locking. If stuck:
Module Not Found
Module Not Found
Issue:
Module not found errorSolution:
Ensure module paths are correct. Modules use relative paths:Module Development
Want to create custom modules or extend existing ones?Module Structure
Module Template
Related Documentation
Backend Setup
Terraform state backend configuration
Multi-Environment Strategy
Dev, staging, production workflows
GKE Production Deployment
Complete production deployment guide
Operations Runbooks
Day-2 operations and troubleshooting
Additional Resources
Comprehensive Module Documentation
Each module includes a detailed README (500-1,000+ lines) with:
- Complete variable reference
- Output documentation
- Usage examples
- Best practices
- Troubleshooting guides