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
terraform destroy is an alias for which command?
- terraform plan -refresh-only
- terraform init -destroy
- terraform apply -destroy
- 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.
Which statements about prevent_destroy are correct?
- It is saved in state, so it survives deleting the resource block
- Terraform rejects any plan that would destroy the protected object
- It stops others from changing the resource in the cloud console
- It makes terraform destroy fail while the protected object exists
- 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.
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.
