nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-003 · Question #204

You use a cloud provider account that is shared with other team members. You previously used Terraform to create a load balancer that listens on port 80. After application changes, you updated the…

The correct answer is B. Terraform will fail with an error because the state file is no longer accurate. Terraform keeps track of the infrastructure state via the state file. When you initially ran terraform plan, Terraform determined that the port should be changed from 80 to 443. However, since another team member manually modified the load balancer, Terraform's local state file…

Use Terraform outside of core workflow

Question

You use a cloud provider account that is shared with other team members. You previously used Terraform to create a load balancer that listens on port 80. After 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 run terraform apply upon returning to your desk?

Options

  • ATerraform will recreate the load balancer.
  • BTerraform will fail with an error because the state file is no longer accurate.
  • CTerraform will change the load balancer port to 80, and then change it back to 443.
  • DTerraform will not make any changes to the load balancer and will update the state file to

How the community answered

(36 responses)
  • A
    3% (1)
  • B
    75% (27)
  • C
    8% (3)
  • D
    14% (5)

Explanation

Terraform keeps track of the infrastructure state via the state file. When you initially ran terraform plan, Terraform determined that the port should be changed from 80 to 443. However, since another team member manually modified the load balancer, Terraform's local state file is now outdated. When you run terraform apply, Terraform will compare the expected state (from the plan) with the actual state (from the provider API). Since the port is already set to 443, but the local state file still shows 80, Terraform will fail with an error due to the state mismatch. To resolve this, you should run terraform refresh or use terraform apply -refresh-only to update the local state before applying changes.

Topics

#terraform apply#state file#drift#concurrency

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-003 Practice