Stale plans and runner isolation
Bind approval to evidence
A stale plan is one that should no longer be used as the approved proposal. Terraform may reject a plan because its prior state no longer matches; that does not mean it detects every external change, policy change or authorization change. Bind approval to the exact commit, plan digest, environment/state identity, policy revision, toolchain and expiry. Use a protected approval record independent of the untrusted job.
commit: synthetic-commit-17plan_digest: synthetic-plan-17state_target: inventory/teststate_revision: 12cli_version: 1.14.8policy_revision: rules-4approval: independent reviewerexpiry: 2027-01-10T12:00:00ZThe values are fictional. A cryptographic digest detects substitution only if the expected digest itself comes from a trusted record. A hash alone does not authenticate a producer. Do not store credentials, full state or sensitive plan values in the approval log.
Respond to changed evidence
Suppose the reviewed commit is C17, and the protected branch advances to C18 before deployment. Even if the original plan file is untouched, our release policy requires a new plan and approval for C18. Terraform may still accept the old plan if state is unchanged; the CI gate must enforce the additional rule.
Approved: commit C17, plan P17, state revision 12Observed: commit C18, plan P17, state revision 12Decision: HOLD -> regenerate -> recheck -> reapproveIf another operator updates state, or a cloud resource changes outside Terraform, discard the old approval and reassess. A change to policies, inputs or provider binaries also invalidates the reviewed context. Do not force a stale plan to run. If a plan is rejected by Terraform, investigate and generate a new one rather than editing state to match it.
Serialize by state identity
CI concurrency reduces overlapping deployments; backend locking protects supported state writes. They solve related but different problems. Use a canonical state identity incorporating backend, state key and workspace; different repositories may share that state. A queue inside one repository does not coordinate other repositories or a human CLI.
Run A -> state inventory/test -> activeRun B -> state inventory/test -> waitRun C -> state inventory/dev -> independent if no shared external dependencyDo not cancel an in-progress apply just to start a newer one. Cancellation can leave partially changed resources. GitHub concurrency has pending-run replacement behavior by default; do not assume FIFO. GitLab resource groups and Azure exclusive locks have their own ordering behavior. Use backend locking where supported and investigate lock ownership before recovery; do not disable locking or force-unlock a live run. Recheck the candidate plan after waiting.
Isolate the runner and credentials
A runner executes jobs; it is a security boundary only when configured and isolated appropriately. Do not allow untrusted fork code to run on a persistent privileged deployment runner, reuse a writable cache from it, or inherit its tokens. Separate runner pools and identities, restrict egress and artifacts, and avoid exposing a Docker socket or internal services. Use short-lived workload federation with tightly bound repository, branch/environment and audience conditions. A read-only cloud role can still expose data. Never use a privileged pull_request_target or workflow_run path to execute untrusted checkout content. A protected branch does not make every external dependency trustworthy.
Fail closed and keep the audit trail
The local practice fixture uses normalized synthetic evidence records, not real plan JSON. A release gate should block mismatched targets, altered artifacts, unknown policy results, expired approvals and unexpected writers.
IF evidence missing or mismatch: HOLDIF state busy: WAIT, then repeat checksIF policy not explicitly allowed: HOLDIF independent approval valid and all identities match: ELIGIBLEELIGIBLE is not proof of runtime successThe model uses a fixed fictional clock and an explicit set of fields; it is not a CI authorization service or a substitute for signature verification. After apply, verify intended outputs and service behavior, retain a redacted change record, and escalate partial failures rather than blindly retrying. Next: troubleshooting and infrastructure incident recovery.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Stale plans and runner isolation — knowledge check
Review trusted delivery and stale-plan decisions.
A new commit replaces the reviewed commit before deployment. What does this lesson require?
Why is a CI concurrency group not sufficient by itself?
A trusted plan digest matches, but the target is different. What should happen?
An otherwise valid candidate finds its state busy. What is the right response?
What is a safer deployment runner design?