Terraform Associate 004 ยท State and backends
Resource drift
Detecting drift via plan and -refresh-only, applying vs reverting drift, out-of-band changes (6d).
Key points
- Drift is when real infrastructure changes outside Terraform.
- Every normal plan refreshes state first, so drift shows up there. terraform plan -refresh-only (and apply -refresh-only) only updates state to match reality and changes no infrastructure.
- To revert drift, run a normal apply; to keep it, update the configuration to match.
Source: https://developer.hashicorp.com/terraform/cli/commands/plan
Practice questions
What is the purpose of terraform apply -refresh-only?
- Update state to match real objects without changing infrastructure
- Force every resource back to what the configuration says
- Destroy resources that no longer match the configuration
- Download the latest provider plugins before planning
Show answer
Answer: A. Update state to match real objects without changing infrastructure
It records changes made outside Terraform into state and outputs, without modifying real infrastructure. It does not enforce the configuration or destroy anything.
Which statements about handling drift are correct?
- A normal plan refreshes state first, so it can reveal drift
- -refresh-only updates state to match changes made outside Terraform
- A normal apply can revert drifted settings to the configured values
- -refresh-only also modifies the remote objects to match the configuration
- -refresh-only can be combined with -destroy in one run
Show answer
Answer: A. A normal plan refreshes state first, so it can reveal drift, B. -refresh-only updates state to match changes made outside Terraform, C. A normal apply can revert drifted settings to the configured values
Normal planning detects drift via refresh, -refresh-only records it without touching infrastructure, and a normal apply pushes real objects back to the configuration. -refresh-only never changes remote objects and cannot be combined with other modes.
True or false: terraform apply -refresh-only changes real cloud resources so that they match your configuration files.
Show answer
Answer: False
False. Refresh-only mode updates the state and root outputs to reflect reality; it leaves the infrastructure alone.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
