Solo developer building practical CLI tools for Linux auditing and B2B data extraction. Creator of Vaultcheck and NPILift. I write about silent failures, false green lights, and infrastructure reliabi
"Proves something narrower than it looks" applies to terraform plan too: it exits 0 whether or not there is a diff, so the CI step that runs plan and trusts the exit code is the same trap one level up. terraform plan -detailed-exitcode gives 0 for no changes, 2 for changes pending, and 1 for an error — gate on 2 and the drift you were chasing fails the build instead of printing green.
@dafili Right, and the codes are documented as you have them: 0 empty diff, 2 non-empty, 1 error.
Though a 2 means config and reality disagree, not that the world moved. On a PR where I've just edited main.tf, a 2 is expected, so failing on it would block every change. It only means drift on a scheduled run against unchanged config.
Solo developer building practical CLI tools for Linux auditing and B2B data extraction. Creator of Vaultcheck and NPILift. I write about silent failures, false green lights, and infrastructure reliabi
The distinction you want isn't in the exit code, it's in the plan body — 2 only says "something changed", so gate on the changed addresses instead: terraform plan -out=tfplan -detailed-exitcode; terraform show -json tfplan | jq -r '[.resource_changes[]? | select(.change.actions != ["no-op"]) | .address] | join(",")', then assert that list is a subset of the module paths the PR touched, and empty on the scheduled run. Same 2, two different predicates, and the PR stops getting blocked. One catch: a moved or import block also lands in resource_changes as non-no-op, so a refactor PR passes the subset check only if you allow those addresses explicitly.
@dafili Agreed on moving the predicate into the plan body, and both your catches are already labelled. A moved resource carries previous_address, and an imported one carries importing, so you can filter on those instead of keeping an allow-list.
And for the scheduled run, resource_drift is the field rather than resource_changes. It's what Terraform detected when comparing the current state to the prior state, which is drift. resource_changes is what it plans to do about it.
Solo developer building practical CLI tools for Linux auditing and B2B data extraction. Creator of Vaultcheck and NPILift. I write about silent failures, false green lights, and infrastructure reliabi
resource_drift[].change.actions uses the same action vocabulary, so that filter is the same loop rather than a second one. One thing worth knowing: a drift-only plan still exits 2 under -detailed-exitcode, but applyable at the top level is false there, which is the cheapest line between "state moved" and "something to apply" if a human has to be paged.
@dafili Right, it's the same loop. The docs say resource_drift uses the same object structure as resource_changes.
On the exit code, I'd expect the opposite, though. 2 means a non-empty diff, so drift that doesn't change anything you'd apply gives you a 0, with the drift sitting in the JSON. Which is the green build from your first comment, come back round. 😄
applyable is a good find. The docs call it whether it makes sense for automation to try applying the plan, which beats what the exit code was answering.
I've spent 16 years finding things that don't work. These days, I also teach AI how to find them.
Somewhere along the way, I started writing stories about AI, work, and life.
Now I run The Third Cup.
I've spent 16 years finding things that don't work. These days, I also teach AI how to find them.
Somewhere along the way, I started writing stories about AI, work, and life.
Now I run The Third Cup.
I'm Honey Kiran. I build and direct AI agents that do real DevOps/SRE work, and I write up the runs — commands, logs, failures and all. This is the code-and-receipts home of Agents on Duty.
"A command succeeded, so what did it actually prove?" is the exact question, and both halves of your day are the same answer: it proved the step ran. Nothing more.
Terraform's state listing proves what Terraform believes. The Azure step's success proved the script executed — while it deleted the placeholder it was meant to fill. Exit codes report on the command. They say nothing about the world.
The habit that survives contact with this: verify the world, not the report of the world. Read back the resource, the file, the live page — whatever the ground truth is — and grade that. Day 94's lesson is worth more than most tooling chapters: success is a claim, and claims get checked.
"Proves something narrower than it looks" applies to
terraform plantoo: it exits 0 whether or not there is a diff, so the CI step that runs plan and trusts the exit code is the same trap one level up.terraform plan -detailed-exitcodegives 0 for no changes, 2 for changes pending, and 1 for an error — gate on 2 and the drift you were chasing fails the build instead of printing green.@dafili Right, and the codes are documented as you have them: 0 empty diff, 2 non-empty, 1 error.
Though a 2 means config and reality disagree, not that the world moved. On a PR where I've just edited main.tf, a 2 is expected, so failing on it would block every change. It only means drift on a scheduled run against unchanged config.
The distinction you want isn't in the exit code, it's in the plan body — 2 only says "something changed", so gate on the changed addresses instead:
terraform plan -out=tfplan -detailed-exitcode; terraform show -json tfplan | jq -r '[.resource_changes[]? | select(.change.actions != ["no-op"]) | .address] | join(",")', then assert that list is a subset of the module paths the PR touched, and empty on the scheduled run. Same 2, two different predicates, and the PR stops getting blocked. One catch: amovedorimportblock also lands in resource_changes as non-no-op, so a refactor PR passes the subset check only if you allow those addresses explicitly.@dafili Agreed on moving the predicate into the plan body, and both your catches are already labelled. A moved resource carries previous_address, and an imported one carries importing, so you can filter on those instead of keeping an allow-list.
And for the scheduled run, resource_drift is the field rather than resource_changes. It's what Terraform detected when comparing the current state to the prior state, which is drift. resource_changes is what it plans to do about it.
resource_drift[].change.actions uses the same action vocabulary, so that filter is the same loop rather than a second one. One thing worth knowing: a drift-only plan still exits 2 under -detailed-exitcode, but applyable at the top level is false there, which is the cheapest line between "state moved" and "something to apply" if a human has to be paged.
@dafili Right, it's the same loop. The docs say resource_drift uses the same object structure as resource_changes.
On the exit code, I'd expect the opposite, though. 2 means a non-empty diff, so drift that doesn't change anything you'd apply gives you a 0, with the drift sitting in the JSON. Which is the green build from your first comment, come back round. 😄
applyable is a good find. The docs call it whether it makes sense for automation to try applying the plan, which beats what the exit code was answering.
Only six will be 100🎉
Six! 😄 I'll finish just in time to start wondering what to do with a free evening. Oh dear me! I still got a chair at the café.
Cheers @xulingfeng
🍻hahaha,cheers!
For your consistency 🙌🙌
Thank you,@csm18 csm. 🙏 Six more, and then I get my evenings back. 😄
"A command succeeded, so what did it actually prove?" is the exact question, and both halves of your day are the same answer: it proved the step ran. Nothing more.
Terraform's state listing proves what Terraform believes. The Azure step's success proved the script executed — while it deleted the placeholder it was meant to fill. Exit codes report on the command. They say nothing about the world.
The habit that survives contact with this: verify the world, not the report of the world. Read back the resource, the file, the live page — whatever the ground truth is — and grade that. Day 94's lesson is worth more than most tooling chapters: success is a claim, and claims get checked.
I like what you said about "Verify the world, not the report of the world", so I would be stealing that. Is really a good habit to have.
The cruel part of the Azure half is that nothing lied to me. The patch honestly reported the placeholder removed, and it was removed. 😄