Overview
MCP Server LangGraph uses Terraform as the Infrastructure as Code (IaC) tool to provision and manage cloud infrastructure across GCP and AWS. This modular approach enables consistent, repeatable, and version-controlled infrastructure deployments.GCP Modules
6 production-ready Terraform modules for GKE
Multi-Environment
Dev, staging, and production configurations
State Management
GCS and S3 backends with locking
AWS Modules
EKS, RDS, ElastiCache modules (96/100 maturity)
Architecture Principles
Modularity
Reusable modules with clear interfaces
- Each cloud resource is a self-contained module
- Modules can be composed for different environments
- No hard-coded values
Environment Parity
Consistent configs across dev/staging/prod
- Same module versions
- Parameter-driven differences (size, HA)
- Promote confidence through consistency
State Isolation
Separate state per environment
- Development:
dev-tfstatebucket/prefix - Staging:
staging-tfstatebucket/prefix - Production:
prod-tfstatebucket/prefix
Module Catalog
GCP Infrastructure
GCP VPC (terraform/modules/gcp-vpc)
GCP VPC (terraform/modules/gcp-vpc)
Purpose: VPC-native networking for GKE with Cloud NATResources:
- VPC with custom subnets
- Secondary IP ranges for pods and services
- Cloud NAT with static IPs
- Firewall rules (IAP, health checks)
- Private Service Connection for Cloud SQL
GKE Autopilot (terraform/modules/gke-autopilot)
GKE Autopilot (terraform/modules/gke-autopilot)
Purpose: Fully managed Kubernetes clusterFeatures:
- Pay-per-pod pricing (40-60% savings)
- Auto-scaling, auto-repair, auto-upgrade
- Workload Identity enabled
- Binary Authorization ready
- Security Posture Dashboard
- Dataplane V2 (eBPF-based)
Cloud SQL (terraform/modules/cloudsql)
Cloud SQL (terraform/modules/cloudsql)
Purpose: Managed PostgreSQL with HAFeatures:
- Regional HA (99.95% SLA)
- Point-in-time recovery
- Read replicas
- Query Insights
- Automatic backups
Memorystore (terraform/modules/memorystore)
Memorystore (terraform/modules/memorystore)
Purpose: Managed Redis with HAFeatures:
- STANDARD_HA tier (99.9% SLA)
- Automatic failover
- Persistence (RDB + AOF)
- Cross-region replicas
Workload Identity (terraform/modules/gke-workload-identity)
Workload Identity (terraform/modules/gke-workload-identity)
Purpose: IAM for Kubernetes podsFeatures:
- No service account keys
- GCP service account per workload
- Granular IAM bindings
- Automatic credential injection
Backend Setup (terraform/backend-setup-gcp)
Backend Setup (terraform/backend-setup-gcp)
Purpose: GCS buckets for Terraform stateFeatures:
- Versioning enabled
- Object lifecycle policies
- Access logging
- Encryption at rest
AWS Infrastructure
AWS infrastructure modules for EKS are already at 96/100 maturity and production-ready. See existing documentation for details.
- VPC with public/private subnets
- EKS cluster with managed node groups
- RDS PostgreSQL with Multi-AZ
- ElastiCache Redis cluster
- IRSA for pod IAM
Directory Structure
State Management
Backend Configuration
- GCP (GCS)
- AWS (S3)
- Automatic state locking
- Versioning enabled
- Encrypted at rest
- Access logs
Environment Strategy
Development
Purpose: Testing and iterationConfiguration:
- Zonal cluster (1 zone)
- Smaller instances
- No read replicas
- BASIC Redis tier
Staging
Purpose: Pre-production validationConfiguration:
- Regional cluster (3 zones)
- Production-like sizing
- HA databases
- Full monitoring
Production
Purpose: Live workloadsConfiguration:
- Regional cluster (3 zones)
- HA for all components
- Read replicas
- Full observability
- Disaster recovery
Deployment Workflow
Best Practices
Module Design
DO: Use semantic versioning for module releases
DO: Validate all inputs with Terraform validation blocks
DO: Provide comprehensive outputs for module consumers
DO: Document all variables with descriptions and examples
State Management
DO: Use separate state per environment
DO: Enable state locking (GCS automatic, S3 with DynamoDB)
DO: Enable versioning on state buckets
DO: Restrict state bucket access (principle of least privilege)
Security
DO: Use Workload Identity (GCP) or IRSA (AWS)
DO: Enable encryption at rest for all data stores
DO: Use private clusters (no public IPs on nodes)
DO: Rotate credentials regularly via Secret Manager/Secrets Manager
Cost Optimization
GKE Autopilot (40-60% savings)
GKE Autopilot (40-60% savings)
Strategy: Pay-per-pod vs. paying for idle nodesImplementation:
- Use GKE Autopilot instead of Standard
- Right-size pod requests (use VPA)
- Enable autoscaling
Committed Use Discounts (25-52%)
Committed Use Discounts (25-52%)
Strategy: Commit to 1-year or 3-year usageImplementation:Savings: 466/month (52%) with 3-year
Resource Right-Sizing
Resource Right-Sizing
Strategy: Match resources to actual usageImplementation:
- Monitor actual CPU/memory usage
- Downgrade oversized Cloud SQL/Redis instances
- Remove unused read replicas
Development Auto-Shutdown
Development Auto-Shutdown
Strategy: Turn off dev environments after hoursImplementation:Savings: $50-70/month per dev environment
Migration Paths
From Manual Infrastructure
From Other IaC Tools
From Pulumi/CDK:- Export resource definitions
- Convert to HCL syntax
- Import state
- Use
former2to generate Terraform - Review and customize
- Import stacks
Troubleshooting
State Lock Conflicts
State Lock Conflicts
Symptom:
Error acquiring the state lockCause: Previous Terraform run didn’t release lock (crash, Ctrl+C)Solution:Backend Initialization Errors
Backend Initialization Errors
Symptom:
Backend configuration changedSolution:Module Version Conflicts
Module Version Conflicts
Symptom:
Module ... does not matchSolution:Permission Denied Errors
Permission Denied Errors
Symptom:
Error 403: The caller does not have permissionSolution: Grant required IAM rolesRelated Documentation
GCP Terraform Modules
Complete guide to all 6 GCP modules
Backend Setup
Initialize Terraform state backends
Multi-Environment
Dev, staging, prod configurations
GKE Production
Deploy to production with Terraform + Kustomize
Next Steps
Set Up State Backend
Review Module Documentation
Choose Environment Strategy
Deploy to Production