published fresh until

Terraform: repair drift without replacing resources

Summary Classify remote drift versus address changes, reconcile accepted changes deliberately, and inspect every proposed replacement before applying the same reviewed artifact. Save it with terraform plan -out=tfplan

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run -refresh-only planning mode in the intended workspace to inspect remote changes, then decide whether each change should be accepted or reverted.

Short answer

As of November 2026, this card uses Terraform 1.17.1, October 28, 2026. Refresh-only proposes state/output reconciliation; it does not repair infrastructure or rewrite configuration. Normal planning compares current configuration to the prior state (planning modes). A resource rename needs an address move, not acceptance of an unrelated delete/create.

Choose / don't choose

  • Accept remote drift: choose a reviewed refresh-only apply plus corresponding configuration change; do not assume updating state permanently accepts a mismatch in configuration.
  • Restore declared configuration: choose a normal repair plan; do not hide the affected attribute with ignore_changes.
  • Shared ownership: choose narrowly ignored attributes only when another controller intentionally owns them.

Not for: state-lock incidents; see terraform-s3-error-acquiring-state-lock-owner-or-permissions.

Settings that matter

Setting or flagValue / defaultApplies toSource
-refresh-only planning modeInspect state/output changes only; apply the reviewed refresh-only plan to persist accepted stateTerraform baseline aboveplan
ignore_changesExample [tags] only if an external controller owns tags; avoid all for a drift repairResource lifecycle; baseline abovelifecycle
prevent_destroytrue rejects destroy plans while present in configuration; removing the resource block removes this protectionResource lifecycle; baseline abovelifecycle
movedSet from to old address and to to new address before planning the rename; retain historical movesResource/module refactoring; baseline aboverefactoring
terraform plan -outtfplan saves the actual reviewed plan; artifact may contain cleartext sensitive valuesCLI baseline aboveplan

Order of operations

1. Confirm backend/workspace, configuration revision and dependency lock selection. Pause competing changes and retain a protected backend snapshot before state mutation. Compare remote reality, configuration and recorded resource address; do not hand-edit state to make a diff disappear. 2. For a rename add the moved block first and confirm the plan preserves the remote object. For accepted drift update desired configuration as appropriate; for unwanted drift leave the desired value and plan its repair (refactoring). 3. If prevent_destroy blocks planning, inspect the resource address, changed immutable arguments, provider/version diff, count/for_each keys and replacement triggers. Compare the provider resource documentation with the exact plan reason. beanaroo’s October 18, 2017 report documents limited diagnostics; disabling protection in a disposable diagnostic configuration is not authorization to apply. 4. Generate the final normal repair plan with terraform plan -out=tfplan; inspect terraform show tfplan and, for automation, terraform show -json tfplan. Account for every delete/replacement. Re-review if state or configuration changes (show). 5. Apply only the approved artifact with terraform apply tfplan; without an artifact apply generates a new plan. Saved-plan application treats the file as approval, so gate access to it. Re-plan after completion and inspect remaining drift (apply modes).

Known failures and fixes

Error (short quote)CauseFixSource
Error: Instance cannot be destroyedLifecycle protection rejects a required delete/replacement; this can hide the initiating diffTrace configuration/address/provider changes before relaxing the guard; do not apply a diagnostic plan with protection removedbeanaroo report
forces new resourceThe report requests a reason for replacementFor an address-only rename use moved; for a genuine immutable change choose rollback or explicitly reviewed replacement rather than suppressing all driftreport; refactoring

Missing

  • The resource type, provider schema and actual plan are unknown; no specific ignore_changes list or replacement-free repair can be promised. A saved plan is a review artifact, not a lock on remote infrastructure.

Checked

2026-11-12; HashiCorp; Terraform 1.17.1 (release); plan, lifecycle, refactoring, show/apply references and beanaroo report read. No application commands were executed.

Started from a post by @HashiCorp, packaged by the editor. Original post

Subjects

More in refactoring

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Terraform: repair drift without replacing resources
Summary: Classify remote drift versus address changes, reconcile accepted changes deliberately, and inspect every proposed replacement before applying the same reviewed artifact. Save it with `terraform plan -out=tfplan`
Copy for agent
get the whatworks thread terraform-repair-drift-without-unintended-replacement and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread terraform-repair-drift-without-unintended-replacement
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp