lifecycle block
A block inside a resource that changes how Terraform replaces or protects it, with settings such as create_before_destroy, prevent_destroy and ignore_changes.
In more detail
create_before_destroy builds the new object before removing the old one, avoiding a gap. ignore_changes stops Terraform undoing edits made outside it to chosen attributes, and replace_triggered_by replaces a resource when another one changes. Keep these rules narrow, because each one hides something from normal planning.
Example
lifecycle {
create_before_destroy = true
ignore_changes = [tags]
}Related terms
- prevent_destroy — A lifecycle setting that makes any plan fail if it would destroy that resource, including as part of a replacement.
- resource replacement — When Terraform must destroy a resource and create a new one because a changed setting cannot be updated in place.
- meta-argument — An argument Terraform itself understands on any resource or module block, such as count, for_each, depends_on, provider and lifecycle.
Taught in
- Tearing It Down With Destroy — Infrastructure as Code with Terraform
- Scaling Resources With Count — Infrastructure as Code with Terraform
- Iterating Over Maps With For Each — Infrastructure as Code with Terraform
- Explicit Dependencies With Depends On — Infrastructure as Code with Terraform
- Safe Changes With Lifecycle Rules — Infrastructure as Code with Terraform
- Provisioners: Why They Are A Last Resort — Infrastructure as Code with Terraform
- The Plan That Wanted To Destroy Production — HashiCorp Terraform Associate (004) Exam Prep
- One Hour, No Weights Published — HashiCorp Terraform Associate (004) Exam Prep
- Resources, Data Sources And The References Between Them — HashiCorp Terraform Associate (004) Exam Prep
- Count, For Each And Dynamic Blocks — HashiCorp Terraform Associate (004) Exam Prep
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Custom Conditions: Validation, Pre And Postconditions, Checks — HashiCorp Terraform Associate (004) Exam Prep
- Drift: When Reality Stops Matching State — HashiCorp Terraform Associate (004) Exam Prep
- Moved And Removed Blocks: Refactoring Without Rebuilding — HashiCorp Terraform Associate (004) Exam Prep