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 questionsThe 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.
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.
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.
Keep practicing
Take the free TERRAFORM-ASSOCIATE-003 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other TERRAFORM-ASSOCIATE-003 practice questions
- Question 1[Understand Terraform Basics and CLI] If you update the version constraint in your Terraf…
- Question 2[Navigate Terraform State and Backends] Terraform variable names are saved in the state f…
- Question 4[Understand Terraform Basics and CLI] You must use different Terraform commands depending…
- Question 6[Understand Terraform Basics and CLI] terraform init creates an example main.tf file in t…
- Question 7[Understand Terraform Basics and CLI] terraform validate confirms that your infrastructur…
- Question 8[Interact with Terraform Modules] All modules published on the official Terraform Module …
