Your Terraform Plan Is Lying: Prompts That Read Drift, Force-New, and the Deletion Line Before Apply

A terraform plan output of 200 lines can hide a single -/+ that recreates your production database. The plan is not a summary — it is a confession, and most engineers skim it. This roundup is about prompts that make an LLM read that confession line by line, cross-check it against state and live infrastructure, and flag what will actually hurt before you type yes.

We'll break down the myths around using LLMs with infrastructure as code, and for each one give a concrete prompt with an input example and a note on what to verify in the answer — because a confident HCL snippet is not a valid plan.

Myth 1: "The model understands my plan output as well as I do"

It does not. An LLM reads text, and the risk is that it invents a resource that isn't in the plan or skips a destroy. The fix is to force it to quote line numbers and never infer.

Task: classify every change in a plan by blast radius.

Prompt:

You are an SRE reviewing a terraform plan before apply. For EACH resource change, output a table: address

| action (create/update/replace/delete) | line number in the plan | does it touch stateful storage or networking | blast radius (low/medium/high). Do not summarize. Do not add resources not present in the text. If an action is 'replace', explain in one sentence WHY terraform chose it based only on the 'forces replacement' lines shown.

What the LLM does well
  • Classify plan changes by blast radius
  • Spot drifted attributes in refresh-only diff
  • Draft idempotent Ansible tasks
  • Map provider errors to causes
What you must still do
  • Run terraform validate
  • Run a real terraform plan
  • Confirm no active run before force-unlock
  • Press apply

Input example: a plan where aws_db_instance.main shows ~ engine_version = "15.4" -> "16.1" # forces replacement.

What to check in the answer: the model should mark that line as replace and high blast radius. If it writes "update in place", it hallucinated — the # forces replacement comment is the ground truth.

Never trust the model's HCL without a gate Any config the LLM produces goes through terraform validate and a real terraform plan before it touches a branch. The model's job is reading and drafting, not approving.

Myth 2: "Drift only shows up when something breaks"

Drift is silent. Someone edits a security group in the console, and state still believes it's locked down. A prompt that compares state to live resources catches this before an audit does.

Task: find resources where live config diverges from state.

Prompt:

Here is `terraform state list` output and the relevant `terraform plan -refresh-only` diff. Identify every resource where the live value differs from state. For each, name the attribute, the state value, the live value, and whether the plan would revert it on next apply. Flag any change to security groups, IAM, or public exposure as 'revert-risky' — reverting might break a manual hotfix someone made during an incident.

What to check: the model must not claim a resource is drifted if it only appears in state list with no diff line. Drift requires an actual attribute difference.

More on the topic: “Your Terraform Plan Is a Confession: How LLM Prompts Catch Drift, Force-New, and Delete-Before-Apply”.

Myth 3: "Ansible roles are idempotent by default"

They are not. A shell: task runs every time. A prompt that audits a role for non-idempotent patterns saves you from a playbook that reconfigures a server on every run.

Task: audit an Ansible role for idempotency breaks.

Prompt:

Review this Ansible role. List every task that is NOT idempotent: raw `shell`/`command` without `creates`/`changed_when`, `lineinfile` without a unique match, tasks that append to a file. For each, propose a corrected version using the proper module (copy, template, blockinfile with markers) and explain why the original re-runs. Output the fixed task as YAML.

Input example:

- name: add repo
  shell: echo "deb ..." >> /etc/apt/sources.list

What to check: the fix should use lineinfile with a regexp or apt_repository, not another shell append. If the model keeps >>, it repeated the bug.

Myth 4: "Provider errors and state locks are just noise"

A state lock error or a provider 403 is the model's chance to be genuinely useful — it can map the error to the exact cause instead of you grepping forums.

Task: diagnose a lock or provider failure.

Prompt:

Here is the exact error text from terraform apply. Identify: (1) is this a state lock, a provider auth failure, or a quota error; (2) the specific resource or backend involved; (3) the safest next command. Do NOT suggest `force-unlock` unless you first list the checks to confirm no other apply is running. Quote the error line you base each conclusion on.

What to check: a responsible answer asks you to verify no active run before unlocking. An answer that jumps straight to force-unlock is dangerous — ignore it.

Where the time actually goes

The pattern across all four: the LLM is fast at reading, classifying, and drafting. It is unreliable at knowing what is safe. Keep the human on the apply button and the validation gate, and let the model do the reading.

If you want the deeper mechanics of how these reviews fit a real workflow, the broader breakdown is here: “Terraform Prompts That Think Like an SRE: Turning an LLM Into a Module Author, Plan Reader, and Drift Hunter”.

The rule that survives every myth: the model reads, the pipeline decides. Treat every answer as a draft to be validated, and the plan stops being a lie you skim.

← All posts

Ask AI about this article

Ask a question about this article — ASI Biont will answer based on its text.