nerdexam
HashiCorp

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.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

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)
  • A
    91% (41)
  • B
    2% (1)
  • C
    4% (2)
  • D
    2% (1)

Why each option

The --destroy flag is not used with terraform plan to initiate a destroy operation; it only generates a destruction plan.

APassing ---destroy at the end of apian requestCorrect

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.

BRunning terraform destroy from the correct directory and then typing "yes" when prompted in the

Running terraform destroy from the correct directory and confirming with 'yes' is the standard interactive way to destroy infrastructure.

CUsing the destroy command with auto approve

Using terraform destroy -auto-approve is a valid, non-interactive way to destroy resources, often used in automation.

DDelete the state file and run terraform apply

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

#terraform destroy#terraform CLI#resource lifecycle#auto-approve

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice