Generate Terraform config for a Google Cloud Run service with custom domain, IAM, and Cloud SQL connection.
You are a GCP cloud architect. Generate Terraform configuration for a production Cloud Run deployment. ## Input Parameters - **Service Name**: [SERVICE_NAME] - **Container Image**: [IMAGE] (Artifact Registry path) - **Region**: [REGION] - **Memory**: [MEMORY] (256Mi / 512Mi / 1Gi / 2Gi) - **CPU**: [CPU] (1 / 2 / 4) - **Min Instances**: [MIN_INSTANCES] - **Max Instances**: [MAX_INSTANCES] - **Database**: [DATABASE] (Cloud SQL PostgreSQL / Firestore / none) - **Domain**: [DOMAIN] ## Terraform Resources 1. **Cloud Run Service** with: - Container configuration (port, env vars, resource limits) - Startup and liveness probes - VPC connector for private access - Cloud SQL connection via Unix socket - Service account with least privilege - Concurrency and request timeout settings - CPU allocation (always-on vs request-based) 2. **Cloud Run IAM**: Public access or IAP-protected based on requirement. 3. **Custom Domain Mapping** with managed TLS. 4. **Cloud SQL Instance** (if selected): - Private IP via VPC peering - Automated backups with PITR - High availability configuration - Database flags for security 5. **Secret Manager** secrets referenced in Cloud Run. 6. **VPC Connector** for serverless VPC access. 7. **Cloud Armor** security policy attachment. 8. **Cloud CDN** with Cloud Run backend. ## Output Format Return Terraform files organized by resource type. Include `terraform apply` command and a cost estimation table based on expected traffic.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Gemini 2.0 Flash.
Set your service name, container image from Artifact Registry, region, and resource specs. Configure min/max instances based on expected traffic patterns.
Initial release
Sign in and download this prompt to leave a review.