Bitzu

Terraform Associate 004 ยท Dependencies, validation and sensitive data

The lifecycle meta-argument

create_before_destroy, prevent_destroy, ignore_changes, replace_triggered_by (4f).

Key points

  • lifecycle tunes how Terraform plans a resource. create_before_destroy builds the replacement first. prevent_destroy errors on any plan that would destroy the resource (deleting the block itself still removes it). ignore_changes lists attributes Terraform should not try to revert. replace_triggered_by forces replacement when a referenced resource or attribute changes.
  • Values must be literals.

Source: https://developer.hashicorp.com/terraform/language/block/resource

Practice questions

Single choice

Which lifecycle argument makes Terraform build a replacement object before removing the old one?

  1. create_before_destroy
  2. prevent_destroy
  3. ignore_changes
  4. replace_triggered_by
Show answer

Answer: A. create_before_destroy

create_before_destroy reverses the default destroy-then-create order. prevent_destroy blocks destruction, ignore_changes skips attributes, replace_triggered_by forces replacement.

Select all that apply

Which statements about prevent_destroy are true?

  1. A plan that would destroy the resource is rejected
  2. Removing the resource block from the configuration is not stopped by it
  3. It prevents other tools from deleting the real object
  4. It can be set from an input variable value
  5. It also stops in-place updates
Show answer

Answer: A. A plan that would destroy the resource is rejected, B. Removing the resource block from the configuration is not stopped by it

A plan that would destroy the resource is rejected with an error. Deleting the resource block from the configuration is not blocked. It is a Terraform-level guard and cannot stop changes made outside Terraform.

True or false

Setting prevent_destroy = true keeps a resource safe even if you delete its block from the configuration.

Show answer

Answer: False

False. The guard only rejects plans that destroy a resource still in the configuration; removing the block removes the protection too.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module