TA-002-P · Question #373
Which of the following is not a way to trigger terraform destroy ?
The correct answer is A. Passing ---destroy at the end of apian request. The --destroy flag is not used with terraform plan to initiate a destroy operation; it only generates a destruction plan.
Question
Which of the following is not a way to trigger terraform destroy ?
Options
- APassing ---destroy at the end of apian request
- BRunning terraform destroy from the correct directory and then typing "yes" when prompted in the
- CUsing the destroy command with auto approve
- DDelete the state file and run terraform apply
How the community answered
(45 responses)- A91% (41)
- B2% (1)
- C4% (2)
- D2% (1)
Why each option
The --destroy flag is not used with terraform plan to initiate a destroy operation; it only generates a destruction plan.
The terraform plan --destroy command (or terraform plan -destroy) generates an execution plan that shows what resources would be destroyed. It does not actually perform the destruction of infrastructure; it only previews the effects of a destroy operation.
Running terraform destroy from the correct directory and confirming with 'yes' is the standard interactive way to destroy infrastructure.
Using terraform destroy -auto-approve is a valid, non-interactive way to destroy resources, often used in automation.
Deleting the state file (terraform.tfstate) causes Terraform to lose track of all managed resources. Subsequently running terraform apply will not destroy infrastructure; instead, it would attempt to provision resources defined in the current configuration, potentially leading to resource duplication or errors, rather than a controlled destruction.
Concept tested: Terraform destroy command and options
Source: https://developer.hashicorp.com/terraform/cli/commands/plan#destroy-planning
Topics
Community Discussion
No community discussion yet for this question.