Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 98


When using Terraform to deploy resources into Azure, which scenarios are true regarding state files? (Choose two.)

Show Answer
Correct Answer: BC

When changes are made to Azure resources outside of Terraform (for example, through the Azure Cloud Console), the state file that Terraform maintains will not be automatically updated. During the next execution of 'terraform plan' or 'terraform apply', Terraform will detect differences between the state file and the actual infrastructure state. While the 'terraform plan' command will highlight these discrepancies, it does not update the state file itself. The 'terraform apply' command, on the other hand, will try to reconcile these differences and update the state file to reflect the current state of the infrastructure, ensuring consistency with the defined configuration.

Discussion

17 comments
Sign in to comment
AzureGurlOptions: BC
Jun 12, 2022

IT should be B and C, however the wording is incorrect, Terraform Refresh will only update the state file for new changes via Az Console Terraform Plan does not change the State file, It will however say the diff in the state. The Terraform apply will make the changes to the state file to keep it consistent. So the wording of Option B is bit ambiguous.

alirasouli
Dec 4, 2022

Option B's wording is too fuzzy.

msingh20
Aug 2, 2023

Terraform plan / apply runs a terraform refresh to update the state with infrastructure so B makes sense.

Tyler2023
Nov 2, 2023

I don't think so, terraform will not generate the configuration changes you've maid manually, terraform apply will remove the configuration you've made that is not included in your tf files

Nikita74Option: C
Oct 1, 2022

Only C

sdm13168Options: BC
May 18, 2023

BC for sure

brax404Options: BC
Oct 17, 2023

B. This is true, but with an important distinction. Terraform doesn't automatically detect changes made outside of it. If you modify resources directly in Azure (outside of Terraform), during the next terraform plan or terraform apply, there might be a discrepancy between the state file and the actual infrastructure. Terraform will then propose to reconcile this difference, which could involve changing or recreating the affected resources. C. This is true. The Terraform state file isn't automatically updated when changes are made outside of Terraform, such as directly in the Azure Cloud Console.

TaalaiOptions: BD
May 23, 2023

according to Chat GPT is B and D

milan92stankovicOptions: BC
Jun 15, 2023

B & C are the correct answer.

March2023Options: BC
Jun 16, 2023

b and c

modarovOptions: BC
Aug 5, 2023

B. When a change is made to the resources via the Azure Cloud Console, Terraform will update the state file to reflect them during the next plan or apply C. When a change is made to the resources via the Azure Cloud Console, the current state file will not be updated

RajmaneOptions: BC
Aug 7, 2023

The right answer is B & C

debabrata6983Options: BC
Aug 27, 2023

The correct answer is B&C

gofavad926Options: BC
Sep 29, 2023

BC When a change is made to the resources via the Azure Cloud Console, the current state file will not be updated. Terraform will update the state file to reflect the changes made to the resources via the Azure Cloud Console during the next plan or apply.

PikopoOptions: BC
Oct 2, 2023

the correct answer are B and C

Tyler2023Options: CD
Nov 2, 2023

I don't think B is an answer here When you change any configuration manually outside your terraform configuration The next time your run terraform apply, terraform will revert your manual changes and follow what is defined in your configuration files So answer i C

mattuyghurOptions: BC
Feb 4, 2024

should be B and C

Absence379Options: BC
Mar 5, 2024

B and C

vibzr2023
Mar 29, 2024

I believe only option C is correct. I tested this by spinning up an EC2 instance in AWS using Terraform and then manually updating the "Name" tag in the AWS console. Immediately after that, when I ran terraform plan, it indicated that the tag would be changed from the Terraform-assigned value ("TerraformCI") to the manually applied value ("Rajesh"). This demonstrates that Terraform detects changes made outside of its management and plans to update the infrastructure accordingly.

vibzr2023
Mar 29, 2024

terraform plan output # aws_instance.ec2_example will be updated in-place ~ resource "aws_instance" "ec2_example" { id = "i-037feb3cac6a58f05" ~ tags = { ~ "Name" = "TerraformCI" -> "Rajesh" } ~ tags_all = { ~ "Name" = "TerraformCI" -> "Rajesh" } terraform apply output update tag from TerraformCI to Rajesh

vibzr2023
Mar 29, 2024

While prevailing sentiment leans towards options B and C, as evidenced by the popularity of ChatGPT's response, I posit that only option C is accurate. Definitive proof of option B's validity hinges on the demonstration of program output reflecting a successful state drift reconciliation. Here is the chatgpt answer when i demonstrated only C is correct. Thank you for providing detailed information about your test and findings. Based on your description, it seems there was a misunderstanding regarding how Terraform interacts with external changes. continued.......

vibzr2023
Mar 29, 2024

When you manually changed the "Name" tag in the AWS console and then ran terraform plan, Terraform compared the actual infrastructure state (with the "Name" tag set to "Rajesh") against what's defined in your Terraform configuration (where the tag might be set to "TerraformCI"). Seeing the discrepancy, Terraform planned to update the resource to match the configuration—changing the tag back to "TerraformCI". This behavior is expected and demonstrates Terraform's goal to ensure the infrastructure matches the configuration specified in your .tf files. continued....

090200fOptions: BC
Jul 14, 2024

B, C are correct answers