Bitzu

Terraform Associate 004 ยท Core Terraform workflow

terraform destroy

Destroy as plan -destroy plus apply, destroying selected resources, prevent_destroy, what is left untouched (3f).

Key points

  • Deprovisions every object managed by the configuration.
  • It is an alias for terraform apply -destroy, so it accepts most apply options (such as -target and -auto-approve) but no plan file; preview it with terraform plan -destroy.
  • Resources outside the configuration are left untouched. lifecycle { prevent_destroy = true } makes Terraform reject plans that would destroy that object, but removing the resource block bypasses it.

Source: https://developer.hashicorp.com/terraform/cli/commands/destroy

Practice questions

Single choice

terraform destroy is an alias for which command?

  1. terraform plan -refresh-only
  2. terraform init -destroy
  3. terraform apply -destroy
  4. terraform state rm
Show answer

Answer: C. terraform apply -destroy

destroy is shorthand for apply in destroy mode. The others record drift, do not exist, or only remove state entries.

Select all that apply

Which statements about prevent_destroy are correct?

  1. It is saved in state, so it survives deleting the resource block
  2. Terraform rejects any plan that would destroy the protected object
  3. It stops others from changing the resource in the cloud console
  4. It makes terraform destroy fail while the protected object exists
  5. It only applies to resources created with count
Show answer

Answer: B. Terraform rejects any plan that would destroy the protected object, D. It makes terraform destroy fail while the protected object exists

With prevent_destroy true, plans that would destroy the object error out, which also blocks terraform destroy. It is not stored in state, so deleting the block removes protection, and it does not control console edits.

True or false

Deleting a resource block from the configuration still leaves prevent_destroy protecting the real object.

Show answer

Answer: False

False. The rule lives in the configuration; once the block is gone, the next apply can destroy the object.

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