TA-002-P · Question #163
What does terraform refresh command do?
The correct answer is E. terraform refresh syncs the state file with the real world infrastructure. terraform refresh queries the provider APIs to reconcile the Terraform state file with the actual current state of real-world infrastructure, detecting drift without modifying infrastructure.
Question
Options
- AA. terraform refresh can be used to selectively update sections of the state file, using
- Bterraform refresh command basically updates the configuration file with the current state
- Cterraform refresh is use to change/modify the infrastructure based on the existing state
- Dterraform refresh can be used to selectively update sections of the state file, using
- Eterraform refresh syncs the state file with the real world infrastructure.
How the community answered
(18 responses)- D6% (1)
- E94% (17)
Why each option
terraform refresh queries the provider APIs to reconcile the Terraform state file with the actual current state of real-world infrastructure, detecting drift without modifying infrastructure.
terraform refresh does not selectively update specific sections of the state file - it performs a full reconciliation of all tracked resources against real-world infrastructure in a single pass.
terraform refresh updates the state file to match real-world infrastructure, not the configuration .tf files - configuration files are authored by users and are never modified by Terraform CLI commands.
terraform refresh does not change or modify infrastructure in any way - only terraform apply with an approved plan makes changes to real resources.
This repeats the incorrect claim that terraform refresh selectively updates state sections, which contradicts its actual behavior of performing a complete state reconciliation.
The terraform refresh command contacts each provider API to read the real-world attributes of every resource tracked in the state file and updates the state to match what actually exists. It surfaces drift between the recorded state and actual infrastructure but never creates, modifies, or destroys any resources.
Concept tested: Terraform refresh state reconciliation with real-world infrastructure
Source: https://developer.hashicorp.com/terraform/cli/commands/refresh
Topics
Community Discussion
No community discussion yet for this question.