TF-004 Use the core Terraform workflow Practice Question
Which THREE of the following are valid reasons to use 'terraform refresh'? (Choose three.)
⚠ Common exam trap
HashiCorp often tests the distinction between `terraform refresh` (state update only) and `terraform import` (adding new resources to state), as well as the misconception that `terraform refresh` modifies configuration files.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
To update the state file when resources were deleted outside of Terraform.
The `terraform refresh` command updates the state file to match real-world infrastructure. Option A is correct because if resources were deleted outside Terraform, refresh removes them from state. Option B is correct because refresh detects drift by comparing state with actual infrastructure. Option D is correct because manual changes to resources are recorded in state after refresh. Option C is incorrect because importing infrastructure requires `terraform import`, not refresh. Option E is incorrect because refresh updates the state file, not the Terraform configuration.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
To update the state file when resources were deleted outside of Terraform.
Why this is correct
terraform refresh reads the current state of real infrastructure and updates the Terraform state file to reflect any changes, including the absence of resources that were previously tracked but have since been deleted manually. This process ensures the state file accurately represents the infrastructure, marking deleted resources as "not found" and preparing them for removal from the state.
- ✓
To detect drift between the state file and actual infrastructure.
Why this is correct
terraform refresh compares the attributes of resources recorded in the Terraform state file with their actual current attributes in the cloud provider or on-premises environment. By updating the state file with these live attributes, it effectively identifies and records any configuration drift that has occurred since the last apply, making the discrepancies visible for subsequent plan operations.
- ✗
To import existing infrastructure into Terraform management.
Why it's wrong here
terraform refresh is designed to synchronize the existing state file with the current reality of resources already managed by Terraform. It does not possess the functionality to bring unmanaged, pre-existing infrastructure into Terraform's control; that specific task is handled exclusively by the terraform import command, which requires mapping existing resources to configuration blocks.
- ✓
To update the state file after making manual changes to resources.
Why this is correct
When manual modifications are made directly to infrastructure resources outside of Terraform (e.g., changing a security group rule via the AWS console), terraform refresh reads these updated attributes from the live infrastructure. It then writes these current values into the Terraform state file, ensuring that the state accurately reflects the post-manual-change configuration and preventing future terraform plan operations from proposing to revert these changes unnecessarily.
- ✗
To update the Terraform configuration with current resource settings.
Why it's wrong here
terraform refresh interacts solely with the Terraform state file, updating its contents to reflect the current attributes of managed infrastructure resources. It explicitly does not modify the .tf configuration files. The configuration files are the desired state definition, which users manually author; refresh only ensures the recorded actual state aligns with reality, not that the desired state definition changes.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.