Exam Terraform Associate All QuestionsBrowse all questions from this exam
Question 195

You have been working in a Cloud provider account that is shared with other team members. You previously used Terraform to create a load balancer that is listening on port 80. After some application changes, you updated the Terraform code to change the port to 443.

You run terraform plan and see that the execution plan shows the port changing from 80 to 443 like you intended, and step away to grab some coffee.

In the meantime, another team member manually changes the load balancer port to 443 through the Cloud provider console before you get back to your desk.

What will happen when you terraform apply upon returning to your desk?

    Correct Answer: B

    When you run terraform apply, it will use the current configuration to create a new execution plan, comparing it against the state file which still shows port 80. Since another team member already changed the port to 443 through the Cloud provider console, Terraform will detect this drift. It will first revert the load balancer port back to what is documented in the state file (port 80), and then apply the intended configuration change (port 443) as specified in the Terraform code. Therefore, Terraform will change the load balancer port to 80, and then change it back to 443.

Discussion
gekkehenkOption: C

As the state is refreshed during the "apply" no changes will be made on the cloud. Terraform will rather update it state file.

Daro_

terraform apply command is not refreshing state, to detect drift without changing state file you need to type: terraform plan -refresh-only terraform apply, will change state file according to configuration file terraform

David_C_90

When you run terraform apply without passing a saved plan file, Terraform automatically creates a new execution plan as if you had run terraform plan, prompts you to approve that plan, and takes the indicated actions. https://developer.hashicorp.com/terraform/cli/commands/apply#automatic-plan-mode

Misiek

The terraform apply command executes the actions proposed in a Terraform plan. Since the plan hasn't been save the plan will run again with apply. Command: plan 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.

shanker_sumitOption: A

option A. Terraform will fail with an error because the state file is no longer accurate. As person has made the changes via the console not through terraform . Hence , it give an error as changes are made outside of terraform.

campsOption: C

It's C

sribalajeOption: C

C is correct answer