TERRAFORM-ASSOCIATE-004 · Question #204
TERRAFORM-ASSOCIATE-004 Question #204: Real Exam Question with Answer & Explanation
The correct answer is B: Terraform will fail with an error because the state file is no longer accurate.. The marked correct answer (B) appears to be incorrect - D is the right answer. When terraform apply runs, Terraform first refreshes its state by querying the actual cloud infrastructure. It discovers the load balancer port is already 443, which matches the desired configuration.
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
Explanation
The marked correct answer (B) appears to be incorrect - D is the right answer.
When terraform apply runs, Terraform first refreshes its state by querying the actual cloud infrastructure. It discovers the load balancer port is already 443, which matches the desired configuration. Since there is no diff, Terraform makes no changes to the load balancer and updates the state file to reflect reality. This is option D.
Why the other options are wrong:
- A - Terraform only recreates resources when an in-place update is impossible (e.g., immutable attributes change). A port match requires no action at all.
- B - Terraform does not error on a stale state file. The refresh step exists precisely to handle out-of-band changes. Errors would occur for things like missing credentials or provider issues, not drift.
- C - Terraform applies are idempotent toward the desired state, not the previous state. It would never deliberately revert to port 80.
Memory tip: Think of terraform apply as "refresh → diff → act." The refresh step means Terraform always checks current reality before deciding what to do - so if someone else already did your job, Terraform shrugs and moves on.
Note: If your exam source marks B as correct, it contains an error. This is a commonly tested Terraform concept and D (no changes + state update) is the accepted correct behavior per HashiCorp's documentation.
Topics
Community Discussion
No community discussion yet for this question.