nerdexam
HashiCorp

TA-002-P · Question #416

You have a Terraform configuration that defines a single virtual machine with no references to it. You have run terraform apply to create the resource, and then removed the resource definition from…

The correct answer is B. Terraform will destroy the virtual machine. If you remove the resource from your config file and the resource is in your state file, terraform will apply the configuration in the config file - which is to delete the resource.

Implement and maintain state

Question

You have a Terraform configuration that defines a single virtual machine with no references to it. You have run terraform apply to create the resource, and then removed the resource definition from your Terraform configuration file. What will happen when you run terraform apply in the working directory again?

Options

  • ANothing
  • BTerraform will destroy the virtual machine
  • CTerraform will error
  • DTerraform will remove the virtual machine from the state file, but the resource will still exist

How the community answered

(50 responses)
  • A
    2% (1)
  • B
    92% (46)
  • C
    2% (1)
  • D
    4% (2)

Explanation

If you remove the resource from your config file and the resource is in your state file, terraform will apply the configuration in the config file - which is to delete the resource.

Topics

#Terraform apply#State management#Resource lifecycle#Desired state

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice