Modular Terraform project for Google Cloud Platform (GCP) to host the Online Boutique app.
- VPC:
prod-vpcwithrouting_mode = "REGIONAL" - Subnets:
gke-subnet(GKE nodes/pods/services)serverless-subnet(Serverless VPC Access)
- Connectivity:
- Private Services Access peering (for Cloud SQL + Memorystore)
- Cloud Router + Cloud NAT for private GKE egress
- Serverless VPC Access connector for Cloud Run
- Compute:
- Regional GKE Standard cluster (private nodes, Workload Identity)
- Optional Cloud Run frontend with all egress through VPC connector
- Data:
- Cloud SQL PostgreSQL (private IP only)
- Memorystore Redis Standard HA (private access)
- Ops:
- Cloud Scheduler HTTP warm-up/health-check every 5 minutes
- Persistent disk + Kubernetes StorageClass for stateful components
.
├── main.tf
├── outputs.tf
├── providers.tf
├── variables.tf
├── versions.tf
└── modules
├── database
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── gke
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── network
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
└── serverless
├── main.tf
├── outputs.tf
└── variables.tf
Set these in terraform.tfvars (or via -var):
project_id = "your-gcp-project-id"
region = "us-central1"
cluster_name = "boutique-gke"Optional:
disk_zone = "us-central1-b"
deploy_cloud_run_frontend = false
frontend_image = "gcr.io/google-samples/microservices-demo/frontend:v0.10.1"
allow_public_frontend = true
deploy_boutique_manifests = true
boutique_namespace = "boutique"
boutique_manifest_url = "https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml"You can deploy the Online Boutique Kubernetes manifests directly from Terraform.
Prerequisites on the machine running Terraform:
gcloudkubectlgke-gcloud-auth-plugin
Why: Terraform uses a local-exec step to run kubectl apply after GKE is created.
Enable in terraform.tfvars:
deploy_cloud_run_frontend = false
deploy_boutique_manifests = true
boutique_namespace = "boutique"Then run:
terraform init
terraform apply -var="project_id=your-gcp-project-id"terraform init
terraform plan
terraform applyYou can deploy infra + app in one flow with:
python3 deploy.py \
--project-id your-gcp-project-id \
--region us-central1 \
--cluster-name boutique-gke \
--auto-approveUseful flags:
--skip-auth(if already authenticated)--skip-terraform(deploy/update app only)--skip-app(infra only)--tfvars-file path/to/terraform.tfvars
gke_cluster_endpointcloud_run_url(null whendeploy_cloud_run_frontend = false)boutique_frontend_external_ipboutique_frontend_urldatabase_private_ip