Transactions

A transaction captures a set of infrastructure changes and tracks them through plan and apply.

Lifecycle

Create → Preview (Plan) → Commit (Apply)

Transaction States

State Description
open Transaction created, changes recorded
previewing Plan is being generated
previewed Plan complete, ready for review
committing Apply is in progress
committed Apply succeeded, state updated
failed Error occurred during preview or commit
aborted Cancelled by user

Create

stategraph tf plan creates a transaction automatically when it detects HCL changes. You can also create transactions manually:

stategraph tx create --tenant <tenant-id>

Or create a transaction and get an API key for it (useful for CI/CD):

export TF_HTTP_PASSWORD=$(stategraph tx create-with-session --tenant <tenant-id>)

Preview (Plan)

stategraph tf plan --out plan.json

Multiple previews can run concurrently against the same state. Each operates on an independent set of resources.

For multi-state plans across directories:

stategraph tf mtx --out plan.json ./networking ./compute

Commit (Apply)

stategraph tf apply plan.json

Before applying, Stategraph runs a conflict check. If another transaction has committed changes to overlapping resources since this transaction was created, the commit is rejected with the conflicting transaction IDs. Re-run stategraph tf plan to pick up the new state and retry.

Abort

Cancel a transaction at any point before commit completes:

stategraph tx abort --tx <tx-id>

Inspect

# List transactions for a tenant
stategraph tx list --tenant <tenant-id>

# View logs for a specific transaction
stategraph tx logs list --tx <tx-id>

See Transaction Commands for the full CLI reference including options, output formats, and CI/CD integration examples.

API Reference

The CLI wraps these API endpoints. Use the API directly for custom integrations.

Endpoint Method Description
/api/v1/tenant/tx/create POST Create a new transaction
/api/v1/tx/{tx_id}/preview POST Start a preview (plan)
/api/v1/tx/{tx_id}/commit POST Commit (apply) the transaction
/api/v1/tx/{tx_id}/abort POST Abort the transaction
/api/v1/tx/{tx_id} GET Get transaction status and details