Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 126


Terraform plan updates your state file.

Show Answer
Correct Answer: B

The terraform plan command does not update your state file. Instead, it generates an execution plan by comparing the desired state (defined in your Terraform configuration files) with the actual state (stored in the state file) of your infrastructure. The plan shows the changes that Terraform will make to the infrastructure without actually applying those changes. The state file is only updated when you run terraform apply, which applies the changes to your infrastructure and updates the state file to reflect the new state.

Discussion

28 comments
Sign in to comment
NunyabiznesOption: B
Sep 27, 2023

B. False The terraform plan command does not update your state file. Instead, it generates an execution plan by comparing the desired state (defined in your Terraform configuration files) with the actual state (stored in the state file) of your infrastructure. The plan shows the changes that Terraform will make to the infrastructure without actually applying those changes. The state file is only updated when you run terraform apply, which applies the changes to your infrastructure and updates the state file to reflect the new state.

Halimb
Mar 7, 2024

A good explanation. If anyone is still doubting this; remember that the state file reflects your actual infrastructure. Since "terraform plan" does not actually change your infrastructure, it would make no sense for it to change your state file. That would make your state file invalid (state drift)!

RVivekOption: A
Mar 26, 2023

Terraform plan always forst check the state of existing resources refreshes/updates that to state. If there is configuration drift from last apply, then terraform will first refresh the state to respreset the current state of the resources, for example if any resouce is deleted or changed that will be upadted in the state and then the chnages to be doe will be displayed

RonZhong
Feb 13, 2024

Yes, everytime when I run Terraform Plan, my backend state file is also updated. I can see the last modified timestamp has been updated, even I didn't apply the change.

secdaddy
Jun 7, 2023

Tested four VMs created via terraform two of the four VMs terminated via aws console ran terraform plan, result is Plan: 2 to add terraform.tfstate was not updated so I'll go with B

Pietjeplukgeluk
Aug 12, 2023

I could not believe this answer, as the documentation is not very clear on updating the file anymore. However, also tested this one, it does READ the remote state, but it does not update the terraform.tfstate indeed. Good answer!

foreverlearner
Jan 1, 2024

"To determine whether state drift occurred, Terraform performs a refresh operation before it begins to build an execution plan. This refresh step pulls the actual state of all of the resources currently tracked in your state file. --> Terraform does not update your actual state file <--, but captures the refreshed state in the plan file." (https://developer.hashicorp.com/terraform/tutorials/cli/plan) "You can also update your state file without making modifications to your infrastructure using the -refresh-only flag for plan and apply operations." (https://developer.hashicorp.com/terraform/tutorials/state/refresh) So plan doesn't update the state file (just an in-memory sync) unless you specify the --refresh-only flag

Uma10Option: B
Mar 1, 2023

The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. The plan command alone will not actually carry out the proposed changes, and so you can use this command to check whether the proposed changes match what you expected before you apply the changes or share your changes with your team for broader review. Source: https://www.terraform.io/cli/commands/plan

BurakkoOption: B
Mar 2, 2023

No, it does not do any changes to the state file.

bora4motionOption: B
Mar 2, 2023

b 100%

milan92stankovicOption: A
Dec 15, 2023

terraform state will UPDATE your state file in case you change the resources outside the terraform. IT will "sync" your state file with the actual infrastructure.

Pinky0289
Mar 13, 2023

Terraform plan command lays out the execution plan, it is only the terraform apply command that makes changes to the state file since it is when the resources are created/updated/destroyed. So, the answer is B. False

DerekKey
Jun 4, 2023

A - true It refreshes state file. Run terraform plan and check file version in you tf file

Bobby1977
Apr 5, 2023

The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan it: Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date. Compares the current configuration to the prior state and noting any differences. Proposes a set of change actions that should, if applied, make the remote objects match the configuration. Answer is A

Fatoch
May 2, 2023

it's B

ArizonaClassics
Jun 7, 2023

Does Terraform plan update remote state? After you configure a remote backend, Terraform will automatically load the state file from that backend every time you run a plan or apply, and it'll automatically store the state file in that backend after each apply, so there's no chance of manual error.

Agil09Option: B
Jul 22, 2023

false. you need terraform apply to change the state file

ale_brd_111Option: B
Jul 31, 2023

b is the correct answer

Ni33Option: B
Nov 9, 2023

B is the correct answer

kudakkOption: B
Feb 19, 2024

The terraform plan command does not change the state of your infrastructure. It creates an execution plan that lets you preview the changes that Terraform plans to make to your infrastructure

nahedOption: A
Feb 29, 2024

terraform state will UPDATE your state file in case you change the resources outside the terraform. IT will "sync" your state file with the actual infrastructure.

gofavad926Option: B
Mar 29, 2024

B, terraform plan doesn't update the state

pamfidelisOption: A
Apr 5, 2024

A. True "You can also update your state file without making modifications to your infrastructure using the -refresh-only flag for plan and apply operations." https://developer.hashicorp.com/terraform/tutorials/state/refresh

TigerInTheCloud
Jun 21, 2024

terraform plan -refresh-only only make the plan of changing state file.

DemonikOption: B
Jun 8, 2024

Nope.Plan does not change state file.But others like apply destroy after approve will :)

vipulchoubisa
Jul 8, 2024

create one simple instance and change the tags from AWS console. After this run terraform plan command. As a result it wont update the state file with new tags. So answer is B

boapaulo
Jul 28, 2024

The terraform plan command does not update the state file. It performs a refresh of the state in-memory to generate an execution plan, but it does not persist these changes to the state file. The state file is updated when you run terraform apply.

91576b8Option: A
Aug 10, 2024

when you run terraform plan , it will refresh the state file automaticlly

dizzy_monkeyOption: A
Sep 9, 2024

"A" should be correct : "Terraform automatically performs the same refreshing actions as a part of creating a plan in both the terraform plan and terraform apply commands." https://developer.hashicorp.com/terraform/cli/commands/refresh

Ajit18
Sep 17, 2024

B. False Terraform plan does not update the state file itself. It performs an in-memory refresh to reconcile the state file with the actual infrastructure, but it doesn't modify the state file on disk. The update to the state file happens during terraform apply if there are changes required.

AkaAka4Option: A
Oct 27, 2024

Refer to https://stackoverflow.com/questions/66240556/terraform-plan-not-updating-state-file

AkaAka4
Oct 27, 2024

Check the 2nd last comment in the link, should be B. Apologies.

55e2078Option: B
Mar 10, 2025

all of this questions same 1:1 as an exam?