Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Terraform Difficulty: Beginner ClaudeChatGPT

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

More Terraform prompts & error guides

Browse every Terraform prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.