TERRAFORM-ASSOCIATE-003 practice question 3 of 30

[Understand Terraform Basics and CLI] You modified your Terraform configuration and run Terraform plan to review the changes. Simultaneously, your teammate manually modified the infrastructure component you are working on. Since you already ran terraform plan locally, the execution plan for terraform apply will be the same.

Full set: 226 questions
Answer options
A: True
B: False
Correct Answer:
[FALSE]
Explanation

The statement is false. By default, when you run terraform apply without a pre-saved plan file, it first runs its own planning phase. This phase includes a "refresh" step where Terraform queries the cloud provider APIs to get the current, real-world state of the infrastructure. In this scenario, the refresh step will detect the manual changes made by the teammate. Consequently, the execution plan generated by terraform apply will be different from the one generated by the earlier terraform plan command, as it will account for this newly discovered "drift" between the state file and the actual infrastructure.

Why Incorrect

The "True" option is incorrect because it presumes that the initial terraform plan output is static and will be used by a subsequent terraform apply. This ignores Terraform's core mechanism for ensuring consistency: refreshing the state from the remote environment before proposing and executing changes. This refresh is crucial for preventing unintended consequences from out-of-band modifications.

References

1. HashiCorp Terraform Documentation

"Command: apply": "By default

apply will also run terraform plan to generate a plan before prompting for approval. This is a convenience feature

and it is recommended to run terraform plan directly and save the plan to a file to be sure that you are applying the changes you expect." This confirms that apply runs its own plan

which includes a refresh.

Source: HashiCorp Developer

developer.hashicorp.com/terraform/cli/commands/apply. Accessed on the current date.

2. HashiCorp Terraform Documentation

"Command: plan": "As part of creating a plan

Terraform reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date. This is what we refer to as a "refresh" of the state." This explains that the planning process

whether invoked by plan or apply

inherently involves a refresh against the real infrastructure.

Source: HashiCorp Developer

developer.hashicorp.com/terraform/cli/commands/plan. Accessed on the current date.

3. HashiCorp Terraform Documentation

"State: Resource Drift": "When the real-world resource differs from Terraform's state file

this is called "drift". [...] When you run terraform plan or terraform apply

Terraform will read the current attributes of the existing resource and update the state file. This detects the drift and may plan to update the resource to match the configuration." This directly addresses the scenario in the question

defining drift and explaining how plan and apply detect and handle it.

Source: HashiCorp Developer

developer.hashicorp.com/terraform/language/state#resource-drift. Accessed on the current date.

Scroll to Top