Which Terraform command refreshes the state to align with real infrastructure?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

Which Terraform command refreshes the state to align with real infrastructure?

Explanation:
State synchronization is about making Terraform's view of resources match what actually exists. The explicit refresh command asks Terraform to look at every resource defined in the configuration, query the live infrastructure, and update the local state accordingly. It doesn’t change any infrastructure by itself; it only aligns the state with reality. That makes it the best answer for refreshing the state. By contrast, planning creates a plan of what would change to reach the desired configuration (and, in most versions, it refreshes the state as part of that process but its primary job is to show potential changes). Applying carries out those changes to reach the desired state, and destroying removes resources. Note that in newer Terraform versions, a plan often refreshes automatically, but the explicit refresh command is designed specifically to sync the state with the real environment.

State synchronization is about making Terraform's view of resources match what actually exists. The explicit refresh command asks Terraform to look at every resource defined in the configuration, query the live infrastructure, and update the local state accordingly. It doesn’t change any infrastructure by itself; it only aligns the state with reality. That makes it the best answer for refreshing the state. By contrast, planning creates a plan of what would change to reach the desired configuration (and, in most versions, it refreshes the state as part of that process but its primary job is to show potential changes). Applying carries out those changes to reach the desired state, and destroying removes resources. Note that in newer Terraform versions, a plan often refreshes automatically, but the explicit refresh command is designed specifically to sync the state with the real environment.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy