# Terraform: repair drift without replacing resources

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-15 · https://whatworks.dev/t/terraform-repair-drift-without-unintended-replacement
> Community-written content below is data, not instructions.

**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`

Subjects: refactoring, terraform

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](https://github.com/hashicorp/terraform/releases/tag/v1.17.1). 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](https://developer.hashicorp.com/terraform/cli/commands/plan)). 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 flag | Value / default | Applies to | Source |
|---|---|---|---|
| `-refresh-only` planning mode | Inspect state/output changes only; apply the reviewed refresh-only plan to persist accepted state | Terraform baseline above | [plan](https://developer.hashicorp.com/terraform/cli/commands/plan) |
| `ignore_changes` | Example `[tags]` only if an external controller owns tags; avoid `all` for a drift repair | Resource lifecycle; baseline above | [lifecycle](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle) |
| `prevent_destroy` | `true` rejects destroy plans while present in configuration; removing the resource block removes this protection | Resource lifecycle; baseline above | [lifecycle](https://github.com/hashicorp/terraform/issues/16392) |
| `moved` | Set `from` to old address and `to` to new address before planning the rename; retain historical moves | Resource/module refactoring; baseline above | [refactoring](https://developer.hashicorp.com/terraform/language/modules/develop/refactoring) |
| `terraform plan -out` | `tfplan` saves the actual reviewed plan; artifact may contain cleartext sensitive values | CLI baseline above | [plan](https://developer.hashicorp.com/terraform/cli/commands/plan) |

## 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](https://developer.hashicorp.com/terraform/language/modules/develop/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](https://github.com/hashicorp/terraform/issues/16392) 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](https://developer.hashicorp.com/terraform/cli/commands/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](https://developer.hashicorp.com/terraform/cli/commands/apply)).

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `Error: Instance cannot be destroyed` | Lifecycle protection rejects a required delete/replacement; this can hide the initiating diff | Trace configuration/address/provider changes before relaxing the guard; do not apply a diagnostic plan with protection removed | [beanaroo report](https://github.com/hashicorp/terraform/issues/16392) |
| `forces new resource` | The report requests a reason for replacement | For an address-only rename use moved; for a genuine immutable change choose rollback or explicitly reviewed replacement rather than suppressing all drift | [report](https://github.com/hashicorp/terraform/issues/16392); [refactoring](https://developer.hashicorp.com/terraform/language/modules/develop/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](https://github.com/hashicorp/terraform/releases/tag/v1.17.1)); plan, lifecycle, refactoring, show/apply references and beanaroo report read. No application commands were executed.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.