nerdexam
HashiCorp

TA-002-P · Question #447

You have created a main.tr Terraform configuration consisting of an application server, a database, and a load balancer. You ran terraform apply and all resources were created successfully. Now you…

The correct answer is B. Terraform will prompt you to confirm that you want to destroy all the infrastructure. Running terraform destroy without flags targets all resources managed by the current configuration and requires interactive confirmation before any deletion occurs.

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

Question

You have created a main.tr Terraform configuration consisting of an application server, a database, and a load balancer. You ran terraform apply and all resources were created successfully. Now you realize that you do not actually need the load balancer so you run terraform destroy without any flags What will happen?

Options

  • ATerraform will destroy the application server because it is listed first in the code
  • BTerraform will prompt you to confirm that you want to destroy all the infrastructure
  • CTerraform will destroy the main.tf file
  • DTerraform will prompt you to pick which resource you want to destroy
  • ETerraform will immediately destroy all the infrastructure

How the community answered

(35 responses)
  • A
    6% (2)
  • B
    89% (31)
  • C
    3% (1)
  • E
    3% (1)

Why each option

Running terraform destroy without flags targets all resources managed by the current configuration and requires interactive confirmation before any deletion occurs.

ATerraform will destroy the application server because it is listed first in the code

Terraform determines the destruction order based on the dependency graph between resources, not the order they appear in the source code files.

BTerraform will prompt you to confirm that you want to destroy all the infrastructureCorrect

By default, terraform destroy pauses and displays the destruction plan showing all resources that will be removed, then presents a yes/no confirmation prompt - the user must type 'yes' explicitly to proceed, preventing accidental deletion of infrastructure.

CTerraform will destroy the main.tf file

terraform destroy only removes the real infrastructure resources tracked in the state file; it never deletes local .tf configuration files.

DTerraform will prompt you to pick which resource you want to destroy

Without a -target flag, terraform destroy does not let you select individual resources - it plans destruction of all managed resources and only prompts for a single yes/no confirmation.

ETerraform will immediately destroy all the infrastructure

Terraform does not immediately destroy anything; it always generates a plan and waits for explicit confirmation unless the -auto-approve flag is passed.

Concept tested: Terraform destroy command behavior and confirmation prompt

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

Topics

#Terraform CLI#terraform destroy#Resource lifecycle#Confirmation prompts

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice