Post

Require plan evidence before Terragrunt apply and report only the failing phase

Require plan evidence before Terragrunt apply and report only the failing phase

I tightened the Terragrunt apply path in two directions at once: an apply can no longer proceed without readable saved plan evidence, and a failed apply now reports only the last recognized phase instead of dumping CLI output into a public log. The push is CI and policy work, so the claims that follow are about test assertions and workflow definitions rather than a live run.

Private apply logs with a fixed phase vocabulary

The protected apply step previously sent CLI output to a discarded stream, leaving an operator to diagnose from exit codes alone. It now writes both output streams into a temporary file created under a restrictive umask and deletes that file on step exit. When the apply fails, the step feeds the captured log into the stage classifier and surfaces one of a fixed list of stage names, followed by a generic error that diagnostics were withheld. The phase tells me where to look without publishing the values themselves. The docs/ci-cd.md and runbook text were rewritten to match, replacing the older statement that both streams were simply discarded.

Plan evidence as a hard gate

The plan helper now renders saved plan JSON through a renamed function that requires both a nonempty plan file and a nonempty rendered output. If either check fails for a retired unit, the script reports that it could not render the saved destroy plan for that unit and returns failure rather than continuing. That failure short-circuits before Conftest runs, so a unit with unreadable plan evidence cannot drift into policy evaluation and pass by default. The accompanying test drives three cases through a synthetic helper, including a missing plan file and a nonzero show exit, and asserts both the error path and the absence of any Conftest call.

Rename-aware scope detection and policy enforcement

Scope detection in the plan workflow now writes changed paths into a temporary file, reads them back null-delimited, and disables rename detection so a moved file keeps its old path in scope. Tests exercise that behavior by committing a policy file, cloning into a fixture, and re-running the scope step. On the policy side, policy/workflows.rego gained a rule describing the exact classified apply command, and the corresponding tests deny nearby variants that read the private log back out, drop the stderr redirect, or change the exit code. One expectation count was reduced, reflecting that the older quiet-deploy pattern no longer applies.

What this changes for a platform team

The reusable idea is treating infrastructure output as sensitive by default and phasing failures through a closed vocabulary rather than free text. A team adopting this pattern gets short, safe failure reports in a public CI log, plus an audit trail proving the pipeline never echoed state. Pairing that with a hard requirement for rendered plan evidence means the policy layer only ever sees plans that genuinely exist. The next check is a real failed apply exercising the phase report end to end; the unit and policy tests establish intent, not runtime confirmation.

This post is licensed under CC BY 4.0 by the author.