Terraform Refresh
Terraform refresh updates the state file to match the real state of your infrastructure. The standalone terraform refresh command is deprecated, and refreshing now happens during plan and apply or through apply -refresh-only.
What Is Terraform Refresh?
Plan and apply already refresh state at the start, so you rarely trigger it by hand.
Bash
terraform plan -refresh-only # preview what would change in stateterraform apply -refresh-only # update state only, no infrastructure changesterraform plan -refresh=false # skip refresh for speed when nothing changed outsideRememberA refresh-only apply updates state only. If your code does not also match, the next normal apply reverts the change.
Frequently Asked Questions
Do I still need to run terraform refresh?
No. Use terraform apply -refresh-only instead, which shows a reviewable diff before updating state.
What is the risk of a careless refresh-only apply?
It accepts whatever exists in the cloud as the new truth, which can record a mistaken manual change instead of fixing it.
Found a mistake, an outdated step or a broken link?