Terraform Module Review Prompt
Get a senior-engineer review of a Terraform module — variable hygiene, state safety, security defaults, drift resistance.
- Target user
- Cloud engineers reviewing Terraform modules before they hit production
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior cloud infrastructure engineer who has shipped Terraform modules to production for years across AWS, GCP, and Azure. You know where modules silently break in real environments.
Review the Terraform module I share. Apply this checklist:
1. **Variables & types**
- Every variable has `type`, `description`, and `default` (or is documented as required)?
- `validation` blocks on inputs that have constraints (CIDR ranges, region names, instance sizes)?
- No untyped `variable "foo" {}` ambiguity?
2. **Outputs**
- Every output has a `description`?
- Sensitive outputs marked `sensitive = true`?
- Outputs are stable identifiers (ARNs, IDs), not transient values?
3. **Resource defaults**
- Encryption-at-rest enabled by default for storage resources (S3, RDS, EBS, etc.)?
- Logging/audit defaults sensible (CloudTrail, VPC flow logs, RDS performance insights)?
- Public access disabled by default (S3 block public access, RDS publicly_accessible = false)?
4. **Tags & naming**
- `tags` merged with a `var.tags` to allow consumer override?
- Resource names use a consistent prefix from `var.name_prefix`?
5. **State safety**
- `lifecycle { prevent_destroy = true }` on stateful resources (RDS, DynamoDB, S3 with data)?
- `ignore_changes` on fields that drift naturally (tags managed by other systems, autoscaled counts)?
- Provider versions pinned with `required_providers` and minimum constraint?
6. **Security**
- IAM roles use least privilege — no `Action: "*"` or `Resource: "*"` unless documented?
- Secrets passed via `aws_secretsmanager_secret` or `data` sources, not literal values?
- Default security groups don't allow 0.0.0.0/0 unless explicitly intended?
7. **Drift resistance**
- `count` and `for_each` are stable across runs (don't depend on changing keys)?
- No use of `random_*` resources without `keepers` to control regeneration?
- Resources that the cloud provider mutates aren't fighting Terraform on every plan?
For each finding: **severity** (critical / warning / nit), **file:line**, **issue**, **HCL diff**.
Module structure (paste `ls -R` and the file contents):
```
[PASTE]
```
Why this prompt works
Most Terraform modules look fine on terraform plan and then bite you in production: missing encryption, no prevent_destroy, public access by default, drift fights. This prompt enforces a real production-grade checklist.
How to use it
- Paste the module structure first (
ls -R modules/foo), then individual.tffiles. Don’t drop the entire module in one massive paste — the model loses fidelity. - After the review, ask: “rewrite the variables.tf and main.tf applying every critical and warning finding.”
- Run
terraform fmt,terraform validate,tflint, andtfsec/checkovon the rewritten module.
Pair this with
tflint— syntax & best practicestfsecorcheckov— security scanningterraform-docs— regenerate README from the moduleinfracost— cost diff per change
What good review output looks like
CRITICAL —
main.tf:42:aws_s3_bucket.thishas noserver_side_encryption_configuration. Add:resource "aws_s3_bucket_server_side_encryption_configuration" "this" { bucket = aws_s3_bucket.this.id rule { apply_server_side_encryption_by_default { sse_algorithm = "AES256" } } }WARNING —
variables.tf:12:var.instance_typehas no type or validation. Consumers can pass"t3.huge"(invalid) and only discover at apply time. Addtype = stringand avalidationblock listing allowed sizes.
Related prompts
-
Ansible Role Generator Prompt
Generate a complete, idempotent Ansible role with proper directory structure, defaults, handlers, molecule tests, and OS-family conditionals.
-
CloudFormation to Terraform Conversion Prompt
Convert an AWS CloudFormation template (YAML or JSON) into idiomatic Terraform HCL — preserving behavior, improving readability.
-
Infrastructure as Code Security Review Prompt
AI security review of Terraform, CloudFormation, or Helm charts — surface dangerous defaults, missing encryption, overly-permissive IAM, and exposed services.
-
Dangerous Terraform Changes Review Prompt
Scan a `terraform plan` output for changes that will silently destroy data, cause outages, or trigger irreversible mutations.