TA-002-P · Question #30
You have used Terraform to create an ephemeral development environment in the cloud and are now ready to destroy all the infrastructure described by your Terraform configuration. To be safe, you would
The correct answer is C. Run terraform state rm *. D. Run terraform destroy and it will first output all the resources that will be deleted before. To safely preview infrastructure deletion, terraform destroy provides a detailed plan of resources to be removed, which you must confirm, while terraform state rm removes resources from Terraform's management within the state file.
Question
You have used Terraform to create an ephemeral development environment in the cloud and are now ready to destroy all the infrastructure described by your Terraform configuration. To be safe, you would like to first see all the infrastructure that will be deleted by Terraform. Which command should you use to show all of the resources that will be deleted? (Choose two.)
Options
- ARun terraform plan -destroy.
- BThis is not possible. You can only show resources that will be created.
- CRun terraform state rm *.
- DRun terraform destroy and it will first output all the resources that will be deleted before
How the community answered
(46 responses)- A2% (1)
- B4% (2)
- C93% (43)
Why each option
To safely preview infrastructure deletion, `terraform destroy` provides a detailed plan of resources to be removed, which you must confirm, while `terraform state rm` removes resources from Terraform's management within the state file.
`terraform plan -destroy` generates an execution plan that explicitly shows exactly what would be destroyed without performing the destruction, serving the purpose of previewing deletions.
It is indeed possible to show resources that will be deleted from the infrastructure, either via `terraform plan -destroy` or by the initial output of `terraform destroy`.
The `terraform state rm` command removes resource instances from the Terraform state and outputs the list of resources being removed, indicating they are no longer managed by Terraform and could be considered for manual deletion or future destructive actions.
Running `terraform destroy` without the `-auto-approve` flag will first generate and display a plan detailing all the infrastructure resources it intends to delete, asking for explicit confirmation before proceeding with the actual destruction.
Concept tested: Terraform destroy workflow and state management
Source: https://developer.hashicorp.com/terraform/cli/commands/destroy
Topics
Community Discussion
No community discussion yet for this question.