Terraform
terraform plan -refresh-only: See Drift Without Changing Anything
What refresh-only plans and applies do, how to read the output, why accepting drift into state doesn't accept it into code, and when to use import instead.
2026-11-17 · 6 min read
terraform plan -refresh-only answers one question: what changed in the real infrastructure since Terraform last looked? It reads every managed resource from your cloud provider, compares it with state, and reports the differences. It never proposes changes to your infrastructure, which makes it the safest way to look for drift.
This guide covers the refresh-only plan and apply, how to read the output, a common misunderstanding about accepting drift, and how refresh-only differs from import.
The commands
| Command | What it does | Changes infrastructure? | Changes state? |
|---|---|---|---|
terraform plan -refresh-only | Shows what changed outside Terraform | No | No |
terraform apply -refresh-only | Shows the same, then asks to record it in state | No | Yes, after you confirm |
terraform refresh | Older command; now the same as apply -refresh-only -auto-approve | No | Yes, without asking |
Refresh-only mode arrived in Terraform 0.15.4, and OpenTofu supports the same flags. Prefer it over terraform refresh, which updates state without showing you anything first.
Reading the output
Say someone added a rule to a security group in the AWS console, and an instance that Terraform manages was terminated by hand. A refresh-only plan shows both (output trimmed):
$ terraform plan -refresh-only
Note: Objects have changed outside of Terraform
# aws_security_group.web has changed
~ resource "aws_security_group" "web" {
~ ingress = [
+ {
+ cidr_blocks = ["0.0.0.0/0"]
+ from_port = 22
+ to_port = 22
+ protocol = "tcp"
},
# (1 unchanged element hidden)
]
}
# aws_instance.worker has been deleted
- resource "aws_instance" "worker" {
- id = "i-0abc123def4567890" -> null
}
This is a refresh-only plan, so Terraform will not take any actions to
undo these.
Read it as a list of things that happened, not things Terraform will do:
- "has changed": the resource still exists, but some attributes differ from state.
- "has been deleted": the resource is gone; Terraform would drop it from state on a refresh-only apply.
- No output: real infrastructure matches state for every managed resource.
Using it as a drift check in CI
Add -detailed-exitcode and the exit code tells a script what happened:
terraform plan -refresh-only -detailed-exitcode -no-color > drift.txt
case $? in
0) echo "No drift" ;;
2) echo "Drift found"; cat drift.txt ;;
*) echo "Plan failed"; exit 1 ;;
esac
Run it on a schedule against each environment, with read-only cloud credentials if your setup allows. The Terraform drift detection guide covers scheduling, classifying findings, and what a plain plan misses.
The common mistake: accepting drift into state isn't accepting it into code
terraform apply -refresh-only updates state to match reality. It's tempting to treat that as "accept this change". It isn't.
Take the security group above. After a refresh-only apply, state includes the port 22 rule. But your code still doesn't. So the next normal terraform plan compares code with state and proposes removing the rule:
# aws_security_group.web will be updated in-place
~ ingress = [
- { from_port = 22, to_port = 22, ... },
]
Every drift finding needs one of three real decisions:
- Keep the change: update the code to match, then confirm a normal plan shows no changes.
- Undo the change: run a normal plan and apply, which puts the resource back to what the code says.
- Keep it for now: record an exception with an owner and an expiry date. If the attribute is legitimately owned by another system,
ignore_changesmay be the right tool, but never for security settings.
A refresh-only apply is mainly useful after a deleted resource (so state stops referring to something that no longer exists), or just before you update the code to match a change you've decided to keep.
What refresh-only can't see
Refresh-only only looks at resources already in your state. It doesn't find:
- Resources created outside Terraform. A bucket someone made in the console isn't in state, so refresh never reads it.
- Resources in a different state file or workspace. Each state is checked separately.
- Changes to attributes the provider doesn't read back. Some write-only values, such as certain passwords, can't be compared.
To find resources that exist in AWS but not in any state, you need an inventory comparison. AWS Config, Resource Explorer or a tag-based inventory can list what exists, which you then compare with terraform state list across workspaces.
Refresh-only vs import
They solve different problems, which is why "terraform refresh only vs import" is a common search:
plan -refresh-only | import block | |
|---|---|---|
| Works on | Resources already in state | Resources not in state yet |
| Question it answers | "What changed outside Terraform?" | "How do I start managing this existing resource?" |
| Changes state | Only with apply -refresh-only | Yes, after a reviewed plan and apply |
| Typical trigger | A scheduled drift check | Someone built something by hand that should be in code |
In practice you use both: refresh-only to catch changes to what you manage, and import for what was never managed. The Terraform import block guide walks through importing AWS resources safely.
Where OrchesTerra fits
A scheduled refresh-only plan tells you that something changed. The hard part is deciding what to do about it across many workspaces and accounts. OrchesTerra checks your AWS accounts against your Terraform on a schedule, finds both changed resources and resources that were never in code, and ranks each finding by risk. Each one goes through an approval: update the code, revert the change, or bring it under Terraform.
Try it in the read-only demo without signing up, or start a 14-day trial with your own account.
Get it as a ranked report
The raw refresh-only output is long and unranked. cloud-drift-report, a free open-source CLI from
OrchesTerra, runs plan -refresh-only -lock=false for you and turns the result into a short report ranked by
severity, with each change explained. It can also list AWS resources that no state file knows about, which
refresh-only can't see:
pip install cloud-drift-report
cloud-drift-report terraform --dir ./infra --format html -o drift.html
cloud-drift-report unmanaged --region us-east-1 --state s3://my-tf-state/prod/
It's read-only and also ships as a GitHub Action and a Claude or Cursor skill. More in A maintained driftctl alternative.
Quick checklist
- Use
terraform plan -refresh-onlyto see drift; it never changes infrastructure or state. - Prefer
apply -refresh-onlyoverterraform refresh, so you see the changes before state is updated. - Add
-detailed-exitcodeand run it on a schedule for a basic drift check. - After accepting drift into state, update the code too, or the next plan will undo it.
- Refresh-only can't find unmanaged resources; use an inventory comparison (cloud-drift-report does one for AWS) and import blocks for those.
