Lifecycle Reference
How an object is replaced, kept, renamed or let go: the lifecycle {} options, host replacement, and the moved and removed blocks. Every plan reads them from the files.
lifecycle {}
Section titled “lifecycle {}”| Option | Effect |
|---|---|
create_before_destroy |
A replace creates the new object before deleting the old: change.actions is ["create","delete"]. Otherwise it is delete-then-create (["delete","create"]). plan.replace counts either. |
ignore_changes |
The listed attribute paths keep their prior value when diffing; all ignores every argument. |
replace_triggered_by |
Replace this object whenever a referenced resource, or attribute, is replaced or changes. |
prevent_destroy |
A plan that would destroy the object fails naming it — a delete, a replace (an argument that forces one, replace, taint, replace_triggered_by), a destroy — and nothing is applied. One value per resource: an expression is accepted, as in OpenTofu (Terraform takes only a literal), so prevent_destroy = var.protect guards while true and releases when false; it must be known at plan and not null, and cannot read count.index or each.key. Inside a module instance the configuration no longer declares (a shrunk module count/for_each), an expression over the module’s inputs cannot be read and the shrink is refused as unknown: only a literal false, or dropping the block, releases it. destroy = false on the same block overrides it (a forget is not a destroy); removing the block lets the delete through. Never disable it, or remove its block, to get a plan through without the user’s say-so. |
destroy |
false forgets the object instead of destroying it — as an orphan, in a destroy, and as the old object of a replace (["forget","create"]) — so the object stays where it is, out of state. The same flag in a removed block: below. |
action_trigger |
Binds an action to the object’s lifecycle (references/actions.md). |
To replace an object though nothing changed, nothing goes in the files: plan({ replace: ["<address>"] }) when the round waits at its plan gate, or taint it.
During a create-before-destroy replace, dependents see the new object as soon as its create applies; the old one is deposed and deleted after. What happens when either half fails: skill_deployment → references/error-handling.md.
Host replacement
Section titled “Host replacement”When a provider is configured from a resource — the kubernetes provider reading kind_cluster.demo.endpoint — replacing that resource raises a question nothing can infer: do the objects that provider serves live inside the host, and so go with it? Often they do (manifests in a cluster); often they do not (an aws provider assuming a role it reads). So it is declared, with the native Terraform mechanism:
resource "kubernetes_manifest" "crd" { # … lifecycle { replace_triggered_by = [kind_cluster.demo.endpoint] }}- With the trigger, replacing the cluster plans the manifest’s delete this round, ordered before the cluster’s own destroy and run through the old cluster, and defers its create to the next round (
provider_config_unknown), which plans it against the new cluster.applycarries it there by itself. - With
create_before_destroyon the contents too, the engine keeps the old host until they move: the contents are tainted and keep serving, the old host stays deposed, and the next round replaces the contents create-before-destroy before the old host is destroyed last. - Without a trigger, nothing is deleted: the contents defer and converge over rounds against the new host, and the round warns, naming them and
replace_triggered_by. Judge it: if they live in the host, declare the trigger; if they only read it, the warning is noise. - Reference an identity attribute of the host (
kind_cluster.demo.endpoint), not the bare resource: a whole-resource reference fires on a mere update of it too. - In a module you own, one cheap resource carrying the trigger, and the module’s resources triggering off it, threads the cascade through the module.
Differs from Terraform: a forced replace (replace, replace_triggered_by) of an object whose provider is configured from something this round applies — and which cannot plan with the unknowns — splits: the delete now, the create next round. A replace the provider requires is never split, and neither is a taint.
Deletes always run through the provider configuration the object was created behind (the block evaluated against prior state), whatever the plan is moving toward: nothing needs declaring for that.
moved — rename without destroying
Section titled “moved — rename without destroying”Change the address in the files and record the move:
moved { from = aws_instance.web to = aws_instance.app}The plan relocates the object and shows no destroy and create. Keep the block until every workspace that holds the old address has applied it. from/to may be resources or module calls. An import into the address a move vacates is refused in the same round: apply the move first.
removed — stop managing without destroying
Section titled “removed — stop managing without destroying”Delete the resource block and declare its removal:
removed { from = aws_s3_bucket.archive lifecycle { destroy = false }}The plan drops the object from state and leaves it running: change.actions ["forget"], counted in plan.forget. Without destroy = false (or without the block at all) deleting the resource block plans a delete. If an address is in both a resource block and a removed block, the resource block wins. Confirm with the user before forgetting: a forgotten object is no longer guarded by anything here. Provisioners in a removed block are refused.
“Remove” (forget it) and “destroy” (delete the object) are different requests; ask which one the user means.
Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.
© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub