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
Multi-Environment
State Management
AWS Modules
Architecture Principles
Modularity
- Each cloud resource is a self-contained module
- Modules can be composed for different environments
- No hard-coded values
Environment Parity
- Same module versions
- Parameter-driven differences (size, HA)
- Promote confidence through consistency
State Isolation
- Development:
dev-tfstatebucket/prefix - Staging:
staging-tfstatebucket/prefix - Production:
prod-tfstatebucket/prefix
Security by Default
- Private clusters (no public IPs)
- Workload Identity (GCP) / IRSA (AWS)
- Encryption at rest and in transit
Module Catalog
GCP Infrastructure
GCP VPC (terraform/modules/gcp-vpc)
GCP VPC (terraform/modules/gcp-vpc)
- 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)
- 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)
- Regional HA (99.95% SLA)
- Point-in-time recovery
- Read replicas
- Query Insights
- Automatic backups
Memorystore (terraform/modules/memorystore)
Memorystore (terraform/modules/memorystore)
- 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)
- 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)
- Versioning enabled
- Object lifecycle policies
- Access logging
- Encryption at rest
AWS Infrastructure
- 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
- Zonal cluster (1 zone)
- Smaller instances
- No read replicas
- BASIC Redis tier
Staging
- Regional cluster (3 zones)
- Production-like sizing
- HA databases
- Full monitoring
Production
- Regional cluster (3 zones)
- HA for all components
- Read replicas
- Full observability
- Disaster recovery
Deployment Workflow
Initialize Backend
Configure Environment
Plan Infrastructure
Apply Changes
Verify Deployment
Best Practices
Module Design
State Management
Security
Cost Optimization
GKE Autopilot (40-60% savings)
GKE Autopilot (40-60% savings)
- Use GKE Autopilot instead of Standard
- Right-size pod requests (use VPA)
- Enable autoscaling
Committed Use Discounts (25-52%)
Committed Use Discounts (25-52%)
Resource Right-Sizing
Resource Right-Sizing
- Monitor actual CPU/memory usage
- Downgrade oversized Cloud SQL/Redis instances
- Remove unused read replicas
Development Auto-Shutdown
Development Auto-Shutdown
Migration Paths
From Manual Infrastructure
Import Existing Resources
Generate Terraform Config
terraform plan to match existing stateGradually Adopt IaC
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
Error acquiring the state lockCause: Previous Terraform run didn’t release lock (crash, Ctrl+C)Solution:Backend Initialization Errors
Backend Initialization Errors
Backend configuration changedSolution:Module Version Conflicts
Module Version Conflicts
Module ... does not matchSolution:Permission Denied Errors
Permission Denied Errors
Error 403: The caller does not have permissionSolution: Grant required IAM rolesRelated Documentation
GCP Terraform Modules
Backend Setup
Multi-Environment
GKE Production
Next Steps
Set Up State Backend
Review Module Documentation
Choose Environment Strategy
Deploy to Production