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

28 comments
Sign in to comment
vitasacOption: D
Nov 3, 2022

for sure response D

Ipergorta
Oct 30, 2022

The answer is D

Tyler2023
May 1, 2024

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

Pinky0289
Mar 17, 2023

I created a VM using terraform config file, and deleted it on the aws console. After issuing terraform apply again, below is the output. <<Apply complete! Resources: 0 added, 0 changed, 0 destroyed.>> Answer is option C. So, the answer is C.

alexik96
Apr 4, 2023

me too. I tested that

chimonsOption: D
Jun 19, 2023

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

bigboi23Option: D
Nov 18, 2022

Offcourse it will be: D Are these answers selected randomly or what?

MofD
Feb 5, 2023

might be examtopics way to get people to buy the contributor access and to participate in discussions

robertninho
Jul 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.

Sunrayk
Nov 12, 2022

Correct answer is D

stalk98
Dec 6, 2022

i tested is C

CHRIS12722222
Dec 19, 2022

pls it should be option D

mifune
Dec 25, 2022

That's impossible unless you alter the terraform.tfstate too

secdaddy
Jun 6, 2023

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
Jun 12, 2023

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
Oct 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
Oct 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.

chaoscreater
Nov 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.

EltoothOption: D
Dec 28, 2022

D is the correct answer.

GHOST1985Option: C
May 19, 2023

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.

vibzr2023
Sep 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.

Ahmad_Terraform
Dec 30, 2022

D is correct , it will recreate the resource, i deleted S3 bucket from the console and then tried terraform apply , and it simply recreated the S3 bucket in AWS.

yogishrb2020
Apr 8, 2023

S3 creation created globally. not region specific like VM.

Oskar_Madin
Jan 3, 2023

Another question, it doesn’t say that you enter yes in prompt or run apply with -auto-approve so it will prompt enter a value then you'll see Plan: 1 to add, 0 changed. however, here is the same You run terraform apply and the VM is created successfully.

yogishrb2020
Apr 8, 2023

when VM deleted from console. there is disconnect from Terraform to Actual infrastructure. how will it recreate ?

ccieman2016Option: C
Apr 9, 2023

If you change any thing, like tags, tf apply recreate resource, if you don’t change and try apply again, nothing happen. So answer is here: “run terraform apply again without changing any Terraform code”. Letter C, I tested too.

Fatoch
Apr 30, 2023

it should be D

Raghav_123
Jun 7, 2023

The ans is C

vadeemkaa
Jun 22, 2023

Definitely the answer is D

Power123
Sep 30, 2023

D is correct

Bluemoon22
Oct 27, 2023

answer is D

HalimbOption: D
Mar 4, 2024

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
Mar 29, 2024

D, the instance will be recreated

Asif_draxiOption: D
Jan 17, 2025

The correct answer is **D. Terraform will recreate the VM**. When you delete the VM manually via the cloud provider's console, the actual infrastructure no longer exists, but Terraform's state file still has a record of the VM. When you run `terraform apply` again, Terraform detects that the VM is missing from the actual infrastructure and will attempt to recreate it to match the configuration defined in the Terraform code.