Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 75


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?

Show Answer
Correct Answer: D

Terraform will recreate the VM. Terraform keeps track of infrastructure resources using a state file. When you delete a VM through the cloud provider's console, the VM is removed in the cloud, but the Terraform state file still believes the VM exists. When you run terraform apply, Terraform first refreshes the state by checking the actual state of resources with what is defined in the configuration. It will detect that the VM is missing and will create a new one to match the configuration specified in the Terraform code.

Discussion

17 comments
Sign in to comment
vitasacOption: D
May 3, 2022

for sure response D

IpergortaOption: D
Apr 30, 2022

The answer is D

chimonsOption: D
Dec 19, 2022

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

Tyler2023Option: D
Nov 1, 2023

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

robertninhoOption: D
Jan 5, 2023

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.

secdaddyOption: D
Dec 6, 2022

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)

adoubanOption: D
Dec 12, 2022

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

lucasbgOption: C
Apr 11, 2023

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.

Mridul31792
Apr 19, 2023

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.

GHOST1985Option: C
Nov 19, 2022

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.

chaoscreaterOption: D
May 26, 2024

The people who answered C are just doomed to fail this exam. This is such a basic foundational knowledge and it's the very core of Terraform and you can't even get this simple one right? This is such a freebie question.

Raghav_123Option: C
Dec 7, 2022

The ans is C

vadeemkaaOption: D
Dec 22, 2022

Definitely the answer is D

Power123Option: D
Mar 30, 2023

D is correct

Bluemoon22Option: D
Apr 27, 2023

answer is D

HalimbOption: D
Sep 4, 2023

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.

gofavad926Option: D
Sep 29, 2023

D, the instance will be recreated

vibzr2023Option: D
Mar 29, 2024

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.