Create Terraform Infrastructure as Code for Cloud Deployment

Generate modular Terraform IaC configurations for cloud infrastructure with networking, compute, database, and security.

๐Ÿ“ The Prompt

Write a modular Terraform configuration to provision a [APPLICATION_DESCRIPTION] infrastructure on [CLOUD_PROVIDER] (AWS, Azure, or GCP). The setup should follow infrastructure-as-code best practices and be ready for a [ENVIRONMENT] environment. **Infrastructure Components:** 1. **Networking:** VPC/VNet with [NUMBER_OF_SUBNETS] subnets across [NUMBER_OF_AZS] availability zones, including public and private subnet tiers, NAT gateway, and appropriate route tables. 2. **Compute:** [COMPUTE_TYPE] resources (e.g., EC2 Auto Scaling Group, ECS Fargate, AKS cluster, GKE cluster) running [APPLICATION_WORKLOAD] with a minimum of [MIN_INSTANCES] and maximum of [MAX_INSTANCES] instances. 3. **Database:** Managed [DATABASE_SERVICE] (e.g., RDS PostgreSQL, Cloud SQL, Azure Database) with [STORAGE_SIZE] GB storage, automated backups, and multi-AZ/replica configuration for high availability. 4. **Load Balancing:** Application load balancer with HTTPS listener using an ACM/managed SSL certificate for domain [DOMAIN_NAME]. 5. **Storage:** Object storage bucket for [STORAGE_PURPOSE] (e.g., static assets, logs, backups) with lifecycle rules and encryption. **Terraform Requirements:** - Use Terraform version >= 1.5 with required_providers block - Organize code into modules: networking, compute, database, load_balancer, storage - Define all configurable values in variables.tf with descriptions, types, and sensible defaults - Output critical values (endpoints, IPs, connection strings) in outputs.tf - Configure remote state backend using [STATE_BACKEND] (e.g., S3 + DynamoDB, GCS, Azure Blob) - Use locals for computed values and consistent tagging strategy with tags: Project=[PROJECT_NAME], Environment=[ENVIRONMENT], ManagedBy=Terraform - Include data sources where appropriate instead of hardcoding AMI IDs or region-specific values **Security:** - Implement least-privilege security groups / firewall rules - Enable encryption at rest and in transit for all applicable services - Use IAM roles/service accounts instead of static credentials **Deliverables:** 1. Complete file structure with main.tf, variables.tf, outputs.tf, providers.tf, and module directories 2. A terraform.tfvars.example file with sample values 3. Brief comments in each file explaining the purpose of each resource block

๐Ÿ’ก Tips for Better Results

Specify your exact cloud provider and region so the AI generates provider-specific resource types and data sources correctly. Describe your application's traffic pattern (e.g., steady, bursty, low-traffic) in the APPLICATION_WORKLOAD placeholder to get appropriate auto-scaling policies. Ask for a companion GitHub Actions or CI/CD pipeline to run terraform plan on PRs and terraform apply on merge for a complete GitOps setup.

๐ŸŽฏ Use Cases

Cloud engineers and platform teams who need to scaffold a complete, modular Terraform project for deploying production infrastructure following best practices.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Refactor Code for Better Performance

Get your code refactored for better performance with Big O analysis and design pattern suggestions.