Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Terraform Associate topic 1 question 75 discussion

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

You have a simple Terraform configuration containing one virtual machine (VM) in a cloud provider. You run terraform apply and the VM is created successfully.
What will happen if you delete the VM using the cloud provider console, and run terraform apply again without changing any Terraform code?

  • A. Terraform will remove the VM from state file
  • B. Terraform will report an error
  • C. Terraform will not make any changes
  • D. Terraform will recreate the VM
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
vitasac
Highly Voted 1 year, 11 months ago
Selected Answer: D
for sure response D
upvoted 17 times
...
Ipergorta
Highly Voted 1 year, 12 months ago
The answer is D
upvoted 6 times
...
vibzr2023
Most Recent 3 weeks, 6 days ago
D. Terraform will recreate the VM When you delete a resource like a VM directly through the cloud provider's console (outside of Terraform), the Terraform state file still believes the resource exists, as it's unaware of any changes made outside its management. The next time you run terraform apply, Terraform compares the desired state (defined in your Terraform configuration) with the actual state (as recorded in the state file and observed in the cloud environment). Since the actual VM no longer exists but your Terraform configuration still defines it, Terraform detects this discrepancy and takes action to reconcile the difference by creating a new VM to match the desired state defined in your Terraform configuration. Terraform's goal is always to make the real-world infrastructure match the configuration.
upvoted 1 times
...
Tyler2023
5 months, 3 weeks ago
I tried this, I created the storage account first by running terraform apply Then I manually deleted the storage account through azure portal Then reran the terraform apply - It refresh the state, which detects that the storage account was gone - Then it re-creates storage account with the same name but without the data from previous instance
upvoted 3 times
...
gofavad926
7 months ago
Selected Answer: D
D, the instance will be recreated
upvoted 1 times
...
Halimb
7 months, 3 weeks ago
Selected Answer: D
D. Stop messing around. This behavior applies to any resource created and managed by Terraform, not just virtual machines, e.g. simple resources like resource groups in Azure (like I've tested with) or any other cloud provider's resources.
upvoted 1 times
...
Bluemoon22
1 year ago
answer is D
upvoted 1 times
...
lucasbg
1 year ago
Selected Answer: C
it`s C for sure. Since the VM was deleted using the cloud web/console, the tfstate will still contain the VM information there, hence nothing will be done. This is drift, and the steps here will be to run terraform -apply | plan -refresh-only, the tfsate will update that the VM was removed and then you will run apply again.
upvoted 3 times
Mridul31792
1 year ago
Correct answer is D as terraform apply implicitly runs terraform refresh before applying the changes which will clear the data of VM from the state file and plan will show to create a new VM.
upvoted 2 times
...
...
Power123
1 year ago
D is correct
upvoted 1 times
...
robertninho
1 year, 3 months ago
Correct answer is D. Terraform will recreate the VM. In Terraform, the state file is used to store the current state of your infrastructure. When you run terraform apply, Terraform compares the state of your infrastructure as defined in the configuration files with the state recorded in the state file, and then makes any necessary changes to bring the infrastructure into compliance with the configuration.
upvoted 4 times
...
vadeemkaa
1 year, 4 months ago
Definitely the answer is D
upvoted 1 times
...
chimons
1 year, 4 months ago
Selected Answer: D
A refresh will be made before apply, therefore terraform will detect the VM is missing, and will update state accordingly. Then, it will create a new one to match configuration
upvoted 5 times
...
adouban
1 year, 4 months ago
Selected Answer: D
I have tested this on my lab on oracle cloud, 1- created a VM using TF 2- Deleted VM manually 3- on Terraform apply, attempted to recreate the instance D is the correct answer
upvoted 3 times
...
Raghav_123
1 year, 4 months ago
The ans is C
upvoted 1 times
...
secdaddy
1 year, 4 months ago
Not sure how you can get C I just did this : 1. created a VM on AWS using terraform apply 2. used the AWS console to delete the VM 3. ran terraform apply again without changing any Terraform code Result : terraform recreated the VM (D)
upvoted 3 times
...
GHOST1985
1 year, 5 months ago
Selected Answer: C
Of course C When you delete from the console you don't remove the VM from the state file so in the next plan or apply terrafom will not apply any changes because from based on the state file the VM is already created.
upvoted 2 times
...
Fatoch
1 year, 5 months ago
it should be D
upvoted 1 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 ...