Write a modular Terraform configuration for an AWS web application stack with pinned providers, least-privilege security groups and managed secrets.
Act as an infrastructure engineer. Write Terraform for the AWS web application stack described below. ## Inputs Application, container image and port: [APP] AWS region and number of Availability Zones: [REGION_AND_AZS] Terraform and AWS provider versions already used by the team: [VERSIONS] Compute sizing, scaling limits and health check path: [COMPUTE] Database engine, version and sizing (or "decide and justify"): [DATABASE] Network access rules (who may reach the load balancer, admin access method): [ACCESS] State backend and module conventions: [CONVENTIONS] ## Instructions 1. Use a `terraform` block with `required_version` and `required_providers` matching the supplied versions. If versions are not supplied, ask or state the versions you assumed. 2. Build a VPC with public subnets for the Application Load Balancer and private subnets for the instances and database, spread across the requested Availability Zones. 3. Run the app on an Auto Scaling group from a launch template; take the AMI from a data source or variable rather than a hard-coded ID. 4. Create security groups so that only the ALB accepts public traffic, instances accept traffic only from the ALB security group, and the database accepts traffic only from the instance security group. 5. Create the database with arguments that exist in the stated provider version. Do not put passwords in code or variables with defaults; use a secrets mechanism (for example RDS-managed master passwords in Secrets Manager) and mark sensitive outputs. 6. Prefer SSM Session Manager over SSH key pairs for admin access unless the inputs require SSH; if SSH is required, restrict it to the supplied CIDR. 7. Split the configuration into modules or files (network, compute, database) and expose inputs through variables with descriptions. ## Return 1. File tree, then each `.tf` file in full. 2. A variables table: name, type, default (if any), description. 3. Commands to run: `terraform fmt -check`, `terraform init`, `terraform validate`, `terraform plan`. 4. Cost and deletion-protection decisions you made and what the user must confirm. 5. Assumptions and any argument you are unsure exists in the stated provider version. ## Acceptance checks No credentials, account IDs or real AMI IDs in code. Every argument must exist in the pinned provider version. Do not claim the plan or apply succeeded; you have not run it.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
App: ghcr.io/acme/notes-api:1.4.2 listening on 8080, health check /healthz Region: eu-west-1, 2 AZs Versions: Terraform >= 1.6, hashicorp/aws ~> 5.0 Compute: t3.small, min 2 max 4 instances Database: PostgreSQL 16, db.t3.micro, 20 GB, single-AZ for staging Access: ALB open on 443 to the internet; no SSH, admins use SSM Conventions: S3 backend with DynamoDB lock table already exists; modules under ./modules
A `terraform` block pinning `hashicorp/aws ~> 5.0`; network, compute and database modules; an ALB security group open on 443 only, an app security group allowing 8080 only from the ALB group, a DB group allowing 5432 only from the app group; an `aws_db_instance` using `db_name` (not the removed `name` argument) and `manage_master_user_password = true` instead of a literal password; an IAM instance profile for SSM and no key pair; and fmt/init/validate/plan commands. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: