This configuration deploys a Google Cloud Run (v2) service with optional global HTTP(S) load balancing. It supports environment variables, secret references, volumes (Cloud SQL, GCS, Secret), VPC access, and container startup probes.
- Terraform
>= 1.4 - Google provider
hashicorp/google>= 5.0 - A container image available in Artifact Registry (
image_url) - Optional for load balancer: a reserved global static IP and, for HTTPS, a DNS-managed domain
- Copy
terraform.tfvars.exampletoterraform.tfvarsand adjust values - Initialize:
terraform init - Plan:
terraform plan - Apply:
terraform apply
project_id(variables.tf:1)region(variables.tf:6)service_name(variables.tf:11)image_url(variables.tf:16)container_port(variables.tf:22)artifact_registry_repo_url(variables.tf:116)
environment_variablesmap for plain env vars (variables.tf:80)secret_environment_variablesmap for secret-backed env vars (variables.tf:86)min_instance_count/max_instance_countfor scaling (variables.tf:50,56)cpu_limitandmemory_limitfor container resources (variables.tf:62,68)vpc_connectorto enable Serverless VPC Access (variables.tf:110)enable_startup_probeand related probe settings (variables.tf:242–276)
- Toggle with
enable_load_balancer(variables.tf:162) - When enabled, provide resource names:
serverless_neg_name,backend_service_name,url_map_name,http_proxy_name,forwarding_rule_name(variables.tf:168–196) - HTTPS support requires:
enable_https,domain_name,ssl_certificate_name,target_https_proxy_name,https_forwarding_rule_name,redirect_url_map_name(variables.tf:205–239)
service_id(outputs.tf:1)service_name(outputs.tf:6)service_url(outputs.tf:11)
- The Cloud Run service resource is defined in
main.tf(main.tf:1) - Global load balancing resources are defined in
load_balancer.tf(load_balancer.tf:3)