Infrastructure as a Database
Infrastructure as a Database keeps your Terraform and OpenTofu state in PostgreSQL as a graph, not as a flat file. You can use it with or without Stategraph Orchestration. See Editions.
What changes
State as a graph
Resources, instances, modules, variables, outputs, and their dependencies are rows in PostgreSQL. You query them with SQL from the CLI or the console. See Query.
Scoped plans
stategraph tf plan compares your local HCL with the current state, and plans only the subgraph that your change reaches, not the full root module. Plan time follows the size of the change, not of your infrastructure.
Stategraph uses the Terraform or OpenTofu binary that you have. You change no providers and no HCL. Replace terraform plan and terraform apply with stategraph tf plan and stategraph tf apply:
stategraph tf plan --tenant <tenant-id> --out plan.json
stategraph tf apply plan.json
Resource-level locks
A usual backend locks the full state file for each operation. Stategraph finds conflicts per resource at commit time, so two engineers can change different parts of the same state at once. See Resource-level locking.
Transactions
Each plan and apply is a transaction, with a log of what changed, in which state, and by whom. You see transactions in the CLI, the console timeline, and SQL. See Transactions.
Multi-state transactions
Several states plan and apply in one atomic transaction, with the references between them resolved. The plan adds the states that your change reaches through terraform_remote_state. stategraph tf mtx plans the directories that you choose, for example the networking, compute, and application layers. See Multi-state transactions.
stategraph tf mtx --tenant <tenant-id> --out plan.json ./networking ./compute ./application
How it works
Your machine or CI runner
Plans and applies run here.
Stategraph Cloud or self-hosted
Stores state and coordinates transactions.
The Stategraph server stores the state in PostgreSQL and coordinates transactions.
- The CLI runs on your machine or CI runner. It reads the Terraform configuration, builds the resource dependency graph, and runs Terraform or OpenTofu, which applies independent changes in parallel, in dependency order.
- The server stores state and coordinates transactions. It does not run your plans and applies.
Get started
- Get a server: Stategraph Cloud or host Stategraph yourself.
- Import a state and run your first plan: see Import your Terraform state for a short walkthrough, or Setup for the full guide.
In this section
| Page | What it covers |
|---|---|
| Setup | API key, CLI setup, import or create a state, workspaces, plan and apply |
| Transactions | Transaction lifecycle: create, preview, commit, abort |
| Resource-level locking | Conflict detection and concurrent transactions |
| Multi-state transactions | Plan and apply several states in one transaction |
| Refactoring | Rename and move resources without losing state |
| Use with Orchestration | Run pull request plans and applies with Infrastructure as a Database |