exam questions

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

Exam Terraform Associate topic 1 question 174 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 174
Topic #: 1
[All Terraform Associate Questions]

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?

  • A. Nothing
  • B. Terraform will destroy the virtual machine
  • C. Terraform will error
  • D. Terraform will remove the virtual machine from the state file, but the resource will still exist
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
chessmaster5000
1 month ago
Selected Answer: B
When you remove a resource definition from your Terraform configuration and then run terraform apply, Terraform will see that the resource exists in the state file but is no longer defined in the configuration. Terraform interprets this as a signal that the resource should no longer exist and will plan to destroy it to match the current configuration. So, when you run terraform apply: -It will show a plan to destroy the VM. -Once you confirm, it will delete the VM from the cloud provider and remove it from the state file. This behavior ensures that the actual infrastructure matches what’s defined in your .tf files.
upvoted 1 times
...
Nick_001
7 months, 2 weeks ago
Selected Answer: B
tested in lab. When reference to resource is removed in config file the next "terraform apply" will destroy the resource. Below is the output from cli # aws_instance.name will be destroyed # (because aws_instance.name is not in configuration)
upvoted 3 times
...
dokaedu
1 year ago
The question is saying removing resource definition of the resource, NOT removing the resource (VM)
upvoted 2 times
...
dokaedu
1 year ago
The question is saying removing the description of the resource, NOT removing the resource (VM)
upvoted 2 times
dnscloud02
1 year ago
definition not description
upvoted 3 times
...
...
depal_dhir
1 year, 1 month ago
Selected Answer: B
This will destroy the VM
upvoted 4 times
...
keiffo2
1 year, 1 month ago
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
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago