code you can match on instead of parsing text.
The flow
- Plan. Send the same files you would apply to a plan call. Nothing is written.
- Read the plan. Check
summary, each changeaction,warnings, and whether the stack needs approval. - Apply with the plan hash. Pass the
hashfrom the plan asexpected_plan_hash. If live state moved, the apply is refused withplan_staleand you plan again. - On a refusal, branch on
code, not on the message.
Where each plan lives
--dry-run with --exit-code exits 2 when changes are pending, so a script can gate on it. The dashboard shows the same plans in the resource import preview and in the stack sync revision view.
Plan shape
A resource or stack plan is one JSON object:actionis one ofcreate,update,delete,noop,error. Anerrorchange has acodefrom the table below and areason.- Created, changed and removed resources are the changes with
create,updateanddelete. - Secret values and env values are never in a plan. Sensitive fields show
(hidden). - A stack plan response adds
issues(validation problems with file and line) and, when the stack needs approval, the apply answers 202 withpending_approvalinstead of changing anything. - An env dry run returns
dry_run: true,changed,env_versionandplan(key names and the kind of change, no values). Passenv_versionback asexpected_versionwhen you apply.
Error codes
Match on thecode field. Released codes are never renamed or reused.
Stack and resource apply codes are listed in full, with what to do for each, in IaC error codes. The ones an agent meets most:
Env apply codes:
Other plain refusals carry a status based code (
validation_failed, forbidden, not_found, conflict, unavailable).
Example
plan_apply (or plan_stack) first, show the summary to the person, then call apply_resources (or apply_stack with confirm: true) with expected_plan_hash set to the plan hash. If it answers plan_stale, plan again.