I wrote a small open-source CLI (MIT, Python) that reads `terraform show -json` / `tofu show -json` output and checks it against a TOML contract before apply. Exit 0 = pass, 1 = violation, 2 = could not judge (fail closed: unknown format, errored/incomplete plan, etc.).
Rules: no-delete, no-replace, scope (allowed addresses), stateful-protect, budget (max changes). Example from a real fixture:
[error] no-replace local_file.hello (local_file) delete,create
planfence: FAIL - 1 violation(s)
No model in the loop: it is plain deterministic code. The tests use real plans from Terraform 1.17.2 and OpenTofu 1.13.9, plus fuzzing against an independent oracle and mutation testing.
Why not a jq one-liner? A replace can show up as delete+create in either order, a moved resource has `previous_address`, and a for_each key rename is a delete + create of different addresses (no-replace does not catch that one, no-delete does). The point is to encode those edge cases once and fail closed on anything it cannot read.
Honest limits: this is not a security audit and does not replace review. If you already use Sentinel/OPA/Conftest you probably don't need it. Drift and output-only changes are ignored by default, and OpenTofu `-target` is not detectable from the plan.
Disclosure: I built this with a lot of help from Claude Code.
Question: where would you expect it to fail open?
pip install planfence
https://github.com/ZahraMost/planfence