orc plan and orc apply
stategraph orc plan and stategraph orc apply run the plan and apply workflows on a checkout, from a terminal or a CI script. The run needs no server, no git operations, and no API calls: it contacts nothing, spawns no git process, and keeps every artefact in the --out directory.
stategraph plan and stategraph apply are pull request comments, not terminal commands: the same words in a pull request comment start a Stategraph Orchestration run. See Pull request commands. This page is about the terminal commands.
When to run locally instead
| Pull request flow | orc plan and orc apply |
|
|---|---|---|
| Starts from | A pull request event, or a stategraph plan comment |
A terminal or CI script on a checkout |
| Server | Stores plans, state, and locks | None: every artefact stays in --out |
| Checks | Policies, security scans, and cost estimates run on each plan | None: only the workflow steps run, and cost estimation is off |
| Locks | An apply locks the directories and workspaces it changes | None |
| Drift detection | Scheduled plans can open issues | None |
A local run suits a sandbox checkout, a one-off experiment, or a CI job that owns its checkout and needs no coordination. For team work on shared infrastructure, stay on the pull request flow: it is where the checks, the locks, and the approval trail live.
Requirements
Both commands read the repository configuration file, .stategraph/config.yml or one of its accepted names, from the working directory. Pass a different file with --config. Without a configuration file the commands fail rather than run with the default configuration.
Both commands take --out=DIR, and it is the only required flag. The --out directory holds the plan files, the state of every dirspace, and the text of every step that ran. It may sit inside the checkout; the walk that finds your Terraform directories skips it.
The walk skips .git, symlinks, and the --out directory, and derives a dirspace from every directory that when_modified.file_patterns matches. A tag query on plan or --tag-query on apply narrows the dirspaces. dir: and workspace: queries work; branch: and dest_branch: queries never match, because a checkout on disk has no branch.
Layers
The layering rules of your configuration carry over from the pull request flow. plan orders dirspaces by depends_on and plan_after, and runs the head layer of what is not applied yet. apply adds one more ordering edge: it also treats apply_after as an ordering edge.
So the cycle for layered infrastructure is plan, apply, plan:
planwrites plan files for the head layer.applyapplies them, which unlocks the next layer.planplans the next layer.
With --iter, orc apply runs this cycle for you: each pass applies the plan files in scope and, when that applied nothing, plans the next layer, asks for approval, and applies it. A pass that applies nothing and plans nothing ends the run. See Layered runs for depends_on, and for a tag query that re-plans a dirspace that is already applied.
Stacks
A stack is an entry under the stacks key of the repository configuration file. Its plan_after, apply_after, and auto_apply rules set the layering edges that a local run orders on, the same edges that the pull request flow uses. See Stacks.
A worked example
A checkout with one module and no changes applied yet:
# .stategraph/config.yml
engine:
name: tofu
# app/main.tf
resource "terraform_data" "stamp" {
input = "v1"
}
Plan the checkout:
stategraph orc plan --out .sgc-out
Output (trimmed):
cwd=app: stdout: OpenTofu has been successfully initialized!
cwd=app: stdout: Plan: 1 to add, 0 to change, 0 to destroy.
The --out directory now holds the plan file, the state of the dirspace, and the text of each step:
.sgc-out
└── app
└── default
├── plan
│ ├── 0_init
│ │ ├── stderr.txt
│ │ └── stdout.txt
│ └── 1_plan
│ ├── stderr.txt
│ └── stdout.txt
├── plan.tfplan
└── state.json
Each dirspace gets <out>/<directory>/<workspace>/; a workspace name is percent-encoded, and the repository root directory maps to the reserved <root> segment.
Apply:
stategraph orc apply --out .sgc-out
Output (trimmed):
cwd=app: stdout: terraform_data.stamp: Creating...
cwd=app: stdout: terraform_data.stamp: Creation complete after 0s [id=5c80d9e7-b42c-5370-7d6e-0d2616119791]
cwd=app: stdout: Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
A plan file that the --out directory already holds applies without a prompt. The approval prompt guards only a fresh plan, as with --iter; the prompt needs an interactive terminal and accepts only the exact word yes. In CI, pass --auto-approve.
The apply deleted plan.tfplan and stored its steps:
.sgc-out
└── app
└── default
├── apply
│ ├── 0_init
│ │ ├── stderr.txt
│ │ └── stdout.txt
│ └── 1_apply
│ ├── stderr.txt
│ └── stdout.txt
├── plan
│ ├── 0_init
│ │ ├── stderr.txt
│ │ └── stdout.txt
│ └── 1_plan
│ ├── stderr.txt
│ └── stdout.txt
└── state.json
A second stategraph orc plan --out .sgc-out prints Nothing to plan. Both commands echo each step as cwd=<dir>: stdout: and cwd=<dir>: stderr: lines, and neither prints a summary line at the end.
For the flags of each command, see Orc Commands.
Limitations
- No locks.
orc applytakes and checks no lock, so two concurrent applies to one checkout can race. Run one at a time. - Plans live only in the
--outtree while they stand. The apply deletes the plan file of every dirspace that it executes, and records the outcome instate.json; there is no other store. A dirspace whose apply failed is planned again on the next run. - No approval before the plan. The prompt guards only the apply of a fresh plan. A plan runs the commands the checkout supplies — the
runsteps of the workflow, thegatesworkflow and hook steps, and theplans.cmdstorage commands — with no confirmation. Runorc planandorc applyonly on a checkout you trust.
Next steps
- Orc Commands: the flags of
orc plan,orc apply,orc indexer, andorc run - Layered runs: order plan and apply across dependent layers
- Stacks:
plan_afterandapply_afterrules across directories - Pull request workflow: the pull request flow that Orchestration automates