Terraform-Associate-004 practice question 21 of 35

What is terraform plan -refresh-only intended to detect?

Full set: 360 questions
Answer options
A: Terraform configuration code changes
B: Corrupt state files
C: State file drift Correct answer
D: Empty state files
Correct Answer:
C. State file drift
Explanation

The terraform plan -refresh-only command is specifically designed to detect "drift," which occurs when the real-world state of infrastructure diverges from the state recorded in Terraform's state file. This command instructs Terraform to query the cloud provider for the current status of all managed resources and compare that against the existing state file. The resulting plan will display any differences found, effectively highlighting changes made outside of Terraform's control. It intentionally ignores any changes made in the Terraform configuration files, focusing exclusively on reconciling the state with reality.

Why Incorrect

A. The -refresh-only flag explicitly tells Terraform to ignore any changes in the configuration code and focus only on the state.
B. While a corrupt state file would likely cause the command to fail, its primary purpose is not to act as a corruption checker.
D. This command operates on existing resources tracked in the state file; an empty state file implies no resources to refresh.

References

1. HashiCorp Terraform Documentation, "Command: plan", Refresh-Only Mode: "The -refresh-only flag is a convenient way to discover any drift between your configuration's state and the real-world infrastructure. This can be useful to detect any changes made outside of Terraform."

2. HashiCorp Learn, "Detect and Manage Drift with Terraform", Detect drift: "You can use the terraform plan or terraform apply commands with the -refresh-only flag to sync the Terraform state with the real-world infrastructure without making any changes. This lets you detect drift in your infrastructure."

3. HashiCorp Terraform Documentation, "Command: apply", Refresh-Only Mode: "The -refresh-only mode is useful when you've made manual changes to the remote objects and want to reconcile the Terraform state with those changes." This directly addresses the concept of drift (manual changes) and reconciliation.

Scroll to Top