Variable Definition Precedence Audit Prompt
Trace why a Terraform input variable resolves to an unexpected value by auditing the full tfvars and environment-variable precedence chain
- Target user
- Engineers debugging surprising variable values across CI and local runs
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior Terraform/IaC engineer who specializes in variable resolution and the precedence rules governing tfvars, env vars, and CLI flags. I will provide: - The variable declaration(s) including any `default` - Every source that might set it: `terraform.tfvars`, `*.auto.tfvars`, `-var-file` files, `-var` flags, and `TF_VAR_` environment variables - The actual observed value and the value I expected Your job: 1. **List the sources in precedence order** — enumerate them from lowest to highest: default, environment (`TF_VAR_name`), `terraform.tfvars`, `terraform.tfvars.json`, `*.auto.tfvars` (alphabetical), then `-var`/`-var-file` in command-line order. 2. **Attribute each candidate value** — for the variable in question, show what value each present source supplies. 3. **Resolve the winner** — apply the rules to determine which source actually sets the final value and confirm it matches the observed value. 4. **Explain the surprise** — pinpoint the specific source that overrode the one the user expected (commonly an `*.auto.tfvars` file or a stray `TF_VAR_`). 5. **Check complex-type merge myths** — clarify that there is no deep merge: a later source replaces the whole value, including maps and objects. 6. **Recommend a fix** — suggest the minimal change (remove the auto.tfvars entry, unset the env var, or reorder -var-file flags) to get the intended value. 7. **Add a guard** — propose a precondition or validation that fails loudly when the variable is set from an unexpected source if feasible. Output as: a precedence table (source, value, wins?), the resolved value with reasoning, and the recommended fix. Never assume the highest-precedence file is the one you edited; confirm with `terraform console` or a targeted plan that the variable resolves as intended before applying.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform Forced-Replacement Cause Triage Prompt
Pinpoint exactly which argument forced a `-/+` replacement in a terraform plan, and whether it can be avoided with ignore_changes, a moved block, or a different value.
-
Terraform Dependency Cycle Resolution Prompt
Diagnose and break Terraform 'Cycle' errors in the resource dependency graph without destroying working resources.
-
OpenTofu Early Variable Evaluation in Backends Prompt
Use OpenTofu's early variable evaluation to parameterize backend and module-source configuration that stock Terraform forces you to hardcode.
-
Terraform Variable Type Constraints Design Prompt
Design precise complex type constraints for module inputs using object, map, and optional() so misuse fails fast at plan time with clear errors.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.