Use it when configuring, checking or troubleshooting Lifecycle in Terraform / OpenTofu.
Lifecycle
Lifecycle settings influence Terraform/OpenTofu resource replacement, destruction protection, change ignoring and dependency-trigger behavior.
1. Lifecycle meta-arguments control behaviour.
2. prevent_destroy for critical resources.
3. create_before_destroy for zero-downtime replacement.
4. ignore_changes for externally managed attributes (document why).
5. replace_triggered_by for dependencies.
resource change → lifecycle rule → plan behaviour
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
Healthy evidence: Lifecycle rules are minimal, reviewed and their plan effects are understood for updates, replacement and destroy.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: ignore_changes masks important drift, create-before-destroy violates quotas/naming, or prevent-destroy blocks legitimate controlled teardown.
Lifecycle rule ≠ business safety guarantee; ignore/protection settings can hide drift or block intended reconciliation.
Step 3 Common mistakes Narrow the fault
ignore_changes = allhiding drift.create_before_destroywith unique names that collide.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Lifecycle rule ≠ business safety guarantee; ignore/protection settings can hide drift or block intended reconciliation.
- Terraform/OpenTofu command success ≠ target workload health; provider operations and application acceptance are separate proof boundaries.
- The same repository ≠ same run when binary, provider/module versions, backend/workspace, variables, credentials or lock selections differ.
- Treat Terraform and OpenTofu as separate implementations: verify behavior against the pinned tool and dependency versions rather than assuming interchangeability.
- lifecycle { prevent_destroy, create_before_destroy, ignore_changes } — rules
terraform plan— effect visible- ignore_changes documented — reasons
ReferenceWhat it is1 section · depth on demand
What it is
The lifecycle block changes how Terraform handles a resource: create_before_destroy, prevent_destroy, ignore_changes, replace_triggered_by.
ReferenceWhy it matters1 section · depth on demand
In depth
The lifecycle block changes how Terraform handles a resource's creation, replacement and deletion. It is the tool for protecting critical resources and avoiding downtime during replacements.
| Setting | Effect |
|---|---|
create_before_destroy | Create the replacement before deleting the old one |
prevent_destroy | Fail any plan that would destroy the resource |
ignore_changes | Ignore differences in listed attributes |
replace_triggered_by | Replace when another resource changes |
precondition / postcondition | Assertions checked during plan/apply |
resource "aws_db_instance" "main" {
lifecycle {
prevent_destroy = true
ignore_changes = [tags["LastBackup"]]
}
}
Use ignore_changes sparingly — it hides drift in those attributes permanently.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Lifecycle rule ≠ business safety guarantee; ignore/protection settings can hide drift or block intended reconciliation.
Example
lifecycle {
prevent_destroy = true
ignore_changes = [tags["last_backup"]]
}
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Terraform / OpenTofu > Lifecycle. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://opentofu.org/docs/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Lifecycle IaC proof-boundary map
Fast definition/state/plan/execution/target-proof boundaries for Lifecycle.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Definition / inputs | Exact revision, toolchain and effective inputs are reproducible | Different runner/version/input context changes evaluation |
| State / planning | Correct backend/state/lock, fresh reads and reviewed graph/plan | Wrong state/workspace, stale reads, unsafe replacement/destroy or missing lock |
| Execution | Expected provider/API operations complete and state persists | Partial apply, auth/API error, ambiguous retry or failed state write |
| Target proof | Independent read-back plus fresh plan confirm intended convergence | Engine success treated as workload acceptance or drift remains unexplained |