how/state
What terraform plan actually compares. Why it refreshes, how three sources become one plan, and what -refresh=false hides.
The familiar picture of git diff is a two-way diff: before and after.
In Terraform there are three diffs, and they form a triangle:
main.tf is the desired state. What you wrote by hand.terraform.tfstate is Terraform's cache. A snapshot of reality as Terraform last saw it.terraform plan first fixes one side of the triangle (state vs cloud, through refresh),
then computes the diff along another (HCL vs state). Press ▶ to see how it comes together.
The baseline position of the triangle: all three sources agree.
Owner = "student".Running plan again now returns No changes. This is the invariant
Terraform always aims for after a successful apply.
recap
The main points about the three-way diff:
plan is refresh + diff, in that order. First state syncs
with the cloud, then it compares against HCL. Reverse the order and you get a mess,
not a plan.-refresh=false skips the first step. The plan becomes fast but blind:
Terraform will not notice if someone edited the cloud by hand. Handy for
local pre-commit checks, dangerous for CI and for a prod plan.terraform plan -refresh-only.
It only gets the updated state, without comparing against HCL. Useful for drift detection.Next: tf-drift on what to do once drift is already visible, and tf-state-mv-rm-import on imperative operations on state.