Solution skill
Terraform workflow: replace tainted and unhealthy resources deliberately
Complete solution
Tainted resources recreate on next apply, which surprises teams when the taint was set long ago. The workflow: audit taints, verify health, untaint or replace with a reviewed plan. Not the full reference manual.
TL;DR: Tainted resources recreate on next apply, which surprises teams when the taint was set long ago. The workflow: audit taints, verify health, untaint or replace with a reviewed plan. Verify current health in the console. A tainted resource that is actually healthy should be untainted (terraform untaint [address]), not recreated.
When
terraform plan shows replacements you did not expect, or you know a resource is unhealthy and needs rebuilding.
Steps
- Audit:
terraform state listwill not show taint directly; the plan output marks tainted resources. Find why each was tainted: failed provisioner, manualterraform taint, or a previous failed apply. - Verify current health in the console. A tainted resource that is actually healthy should be untainted (
terraform untaint [address]), not recreated. Taint is a claim about health; check the claim. - For genuinely unhealthy resources:
terraform apply -replace=[address]forces replacement with a reviewed plan. Prefer-replaceovertaint+ apply: it is explicit, single-shot, and does not leave taint state lying around for the next person. - For config-driven replacement (replace when a secret or AMI changes):
replace_triggered_byin lifecycle makes the replacement automatic and reviewable in the plan.
Rules for agents
- Never untaint a resource you have not verified. Untainting a genuinely broken object just postpones the failure to the worst moment.
terraform taintis deprecated in favor of-replace. If you see taint in runbooks, update the runbook.- Replacement of stateful resources destroys data unless the resource handles it (snapshots, replication). Check the data story before replacing anything stateful.
- After replacement, the plan is clean and the new object is healthy in the console. Both, not either.
When to use this
- This covers exactly what the title says: Terraform workflow.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Terraform; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Compatibility
- Not pinned to a specific version; follows current Terraform behavior.
Edge cases
- Replacement of stateful resources destroys data unless the resource handles it (snapshots, replication).
Evidence
taint marks resources for recreation; -replace forces replacement for one apply; replacetriggeredby triggers replacement from config. Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_whvliQYDGrEGwVjdMNzUHg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform workflow: replace tainted and unhealthy resources deliberately <span>— Vectle</span></a>