Terraform AWS Infrastructure Generator
devops
HCL
scaffolding
strict_senior
Generate complete Terraform code for AWS infrastructure including VPC, EC2, RDS, S3, and all necessary resources.
By lucas_a
12/8/2025
Prompt
Generate complete Terraform code to provision AWS infrastructure with the following specifications:
Project Configuration
- Project Name: [e.g., myapp, production-api]
- Environment: [dev / staging / production]
- AWS Region: [e.g., us-east-1, eu-west-1]
- Terraform State Backend: [S3 bucket name for state file]
VPC Configuration
- VPC CIDR Block: [e.g., 10.0.0.0/16]
- Number of Public Subnets: [e.g., 2]
- Number of Private Subnets: [e.g., 2]
- Enable NAT Gateway: [Yes / No]
- Enable VPN Gateway: [Yes / No]
EC2 Configuration
- Instance Type: [e.g., t3.micro, t3.medium, m5.large]
- AMI: [Ubuntu / Amazon Linux 2 / Custom]
- Number of Instances: [e.g., 2]
- Auto Scaling: [Yes / No]
- Min Instances: [if auto scaling]
- Max Instances: [if auto scaling]
- SSH Key Name: [existing key pair name]
- User Data Script: [Describe initialization scripts needed, e.g., "Install Docker and start app"]
- Security Group Rules:
- Inbound: [List ports and sources, e.g., "80 from 0.0.0.0/0", "443 from 0.0.0.0/0", "22 from office IP"]
- Outbound: [Usually allow all]
RDS Database Configuration
- Engine: [postgres / mysql / mariadb]
- Engine Version: [e.g., 15.3, 8.0]
- Instance Class: [e.g., db.t3.micro, db.t3.small]
- Allocated Storage: [GB, e.g., 20]
- Max Allocated Storage: [GB, e.g., 100]
- Database Name: [initial database name]
- Multi-AZ: [Yes / No]
- Backup Retention: [days, e.g., 7]
- Storage Encryption: [Yes / No]
- Publicly Accessible: [Yes / No]
S3 Buckets
List all S3 buckets needed:
- Bucket 1: [name and purpose, e.g., "app-assets for static files"]
- Versioning: [Enabled / Disabled]
- Public Access: [Block / Allow]
- Lifecycle Rules: [Yes / No]
- Bucket 2: [name and purpose]
- [Configuration details]
Additional AWS Resources (Optional)
- CloudFront Distribution: [Yes / No]
- Route53 Hosted Zone: [Domain name if needed]
- Application Load Balancer: [Yes / No]
- ElastiCache Redis: [Yes / No]
- SNS Topics: [List topics if needed]
- SQS Queues: [List queues if needed]
Security & IAM
- IAM Roles Needed: [List roles, e.g., "EC2 role with S3 read access"]
- IAM Policies: [Describe custom policies needed]
- Security Groups: [List all security groups beyond EC2]
Tags
Standard tags to apply to all resources:
Project: [project name]Environment: [environment]ManagedBy: Terraform- [Additional custom tags]
Outputs Required
What values should be output:
- VPC ID
- Subnet IDs
- EC2 Instance IPs
- RDS Endpoint
- S3 Bucket Names
- Load Balancer DNS
- [Additional outputs]
Deliverables
Generate the following Terraform files:
- main.tf - Provider configuration, backend setup, data sources
- variables.tf - All input variables with descriptions and defaults
- outputs.tf - All output values
- vpc.tf - VPC, subnets, internet gateway, NAT gateway, route tables
- ec2.tf - EC2 instances, security groups, key pairs, user data
- rds.tf - RDS instance, subnet group, parameter group, security group
- s3.tf - S3 buckets with versioning, encryption, and access policies
- iam.tf - IAM roles, policies, and instance profiles
- terraform.tfvars.example - Example variable values
All code should:
- Follow Terraform best practices
- Use variables for all configurable values
- Include descriptive comments
- Implement proper security (encryption, private subnets, security groups)
- Use remote state backend (S3)
- Include proper resource dependencies
- Add appropriate tags to all resources
Generate production-ready Terraform code ready to run with terraform init, terraform plan, and terraform apply.
Tags
terraform
aws
iac
infrastructure
Tested Models
gpt-4
claude-3-opus