Workspaces and backends
A workspace is a backend and a state slot, bound to a configuration by open. Most runs use one, the
default. To work on staging and production side by side, open more, each under its own alias; Turf™
then names each by that alias in every later call.
Example configuration: turf-examples/terraform/kubernetes/kind-crd
listopen
The backend lists only default. I opened staging under the alias staging, keeping
cluster_name = "turf-crd-staging" for it while it is open. It has no statefile yet: the first up
writes one, at terraform.tfstate.d/staging/terraform.tfstate. Calls that name no alias still go to
the default workspace.
TOOL RESULTopen
workspace_alias: "staging" config_alias: "default" workspace_name: "staging"backend_type: "local"state_path: "…/kind-crd/terraform.tfstate.d/staging/terraform.tfstate"resource_count: 0warnings: [ "…the declared path does not apply to this workspace…" ]up→awaiting_planplan→awaiting_approval
On staging: Plan: 1 to add, 2 deferred to a later round.
+ kind_cluster.demo name: turf-crd-staging-1Ready to apply these changes?
illustrative · the shape of a session, not a transcript
Ask in words:
- “What workspaces does this configuration have?” (
list) - “What’s open?” (
status) - “Open the staging workspace” (
open, with an alias when another is already open) - “Close staging” (
close) - “Delete the staging workspace” (
delete, afterclose)
The agent tells you when open reports a run already holding the workspace, and asks before it ends
one or force-unlocks anything.
The CLI has no workspace commands. Ask its agent, interactively or in one shot:
cd path/to/config && turf chatcd path/to/config && turf exec "what workspaces exist?"How it works
Section titled “How it works”Alias and name. The workspace name belongs to the backend: the OpenTofu® workspace, a state slot,
what terraform.workspace reads. The alias is the server’s handle for an open workspace. Omit the
alias (or use "default") and every tool targets that workspace when a call passes no
workspace_alias, however many others are open. Name one ("staging", "prod") to open several at
once, and pass it to every later call. Opening a workspace already open under the same alias, the same
way, returns it as it is.
Two workspaces may share one configuration and differ in var values and workspace_name. Prefer
var values as the difference: they reach the backend block, the provider blocks and the resources,
while the workspace name reaches none of them. workspace_name addresses state that a
tofu workspace select user created.
The backend comes from the configuration. A workspace opens against a configuration (config_alias,
omitted for the one init registered without an alias) and stays bound to it. The backend is the
configuration’s backend block. backend_config and backend_config_files supply only what the block
leaves out, such as credentials and per-environment values, merged key by key as
tofu init -backend-config does. A key the backend declares as a block is a nested object:
{ "workspaces": { "name": "…" } }{ "assume_role": { "role_arn": "…" } }The first is for remote, the second for s3. backend_type is only for a configuration that
declares no backend; one that contradicts a declared backend is refused, so edit the block to move the
store. The providers are what the configuration requires: open takes none.
Backend credentials are read by the MCP server, from its own environment, not the engine’s. See Where credentials are read.
The remote backend (the protocol of HashiCorp’s hosted platform, of Terraform® Enterprise and of Scalr) is supported for state
storage and locking only: point it at a workspace whose execution mode is local. Its token comes from
turf login <host> or TF_TOKEN_<host>.
Moving a backend. The engine records which backend each workspace’s state lives in. An open that
reaches the same state through a different backend is refused at the next plan (“lineage … is bound to
backend … and this open arrives from a different backend”). When the move is deliberate, open again with
reconfigure: true, as tofu init -reconfigure. A statefile copied to a second backend is refused
regardless: it needs a new lineage.
Where a named workspace’s state lands. A backend’s path addresses the default workspace only.
Every other name is stored under the configuration directory, at
terraform.tfstate.d/<name>/terraform.tfstate. open returns state_path already resolved, and warns
when a declared path does not apply.
Open for this session. Workspace bindings belong to the server’s session; runs do not. A workspace
stays open across turns until close, which ends the binding and changes nothing in the configuration
or the state. When the session ends, open workspaces close, and a run the server was following is
detached, never cancelled: it waits in the engine, and a later open reports it.
The state lock
Section titled “The state lock”open reads the state without locking it. The engine takes the state lock while a run is going, and
holds it through every pause, at an approval point and at turf actions, as tofu apply holds it at its
prompt. A detached run gives it back.
When a call fails with “the state is already locked by another tofu client”:
- Check for a run first.
openandstatusreport one holding the workspace, from this server or an earlier one. Pick it up withapply, or end it withcancel. Never force-unlock it. - Otherwise ask the user. The lock may belong to an active operation in another tool, terminal or CI job, and force-unlocking an active lock can corrupt state.
- Only on an explicit yes, open with
force_unlock: true. - Refused with “lock ID … does not match existing lock ID”? The backend names the lock by something
else: pass the ID the error names as
lock_id. Theremotebackend wants"<organization>/<workspace>". Some hosts (Scalr) do not implement force-unlock over the API: clear the lock in the host’s own interface.
status, list and delete
Section titled “status, list and delete”status lists what is open here: each workspace’s alias, configuration, backend, lineage, and the
run holding it (its kind, stage, round, open questions, next, and its drift block when its
up asked for drift detection). It also lists the planfiles
a workspace holds, and its open drift notices.
list lists the workspaces in the configuration’s backend, as tofu workspace list: "default"
first, the rest sorted. It is refused when the backend block reads terraform.workspace: each workspace
then keeps its state in a store of its own, and a list of one store would pass for the whole set.
delete removes a workspace’s state from the backend, as tofu workspace delete. Close it first.
It is refused for default, for a name list does not show, for an open workspace, and for one a run
holds (cancel it first). A workspace whose state holds resources needs force: true, which removes
the state, never the cloud resources: they stop being tracked. To delete the resources, destroy first.
A resource_count of 0 where you expected resources means you addressed the wrong store.
Arguments
Section titled “Arguments”open:
| Argument | Meaning |
|---|---|
config_alias |
The configuration, as init registered it. Omit it for the one registered without an alias. |
workspace_name |
The backend’s workspace name. Defaults to default. |
workspace_alias |
The alias every later call passes. Omit it for the default workspace. |
backend_config |
Backend settings merged over the declared ones, key by key, these winning. |
backend_config_files |
Backend settings files, in order, merged below backend_config. |
backend_type |
For a configuration that declares no backend. Refused against a declared one. |
var, var_file |
Variable values kept for the workspace while it is open. See Variables and var files. |
reconfigure |
Consent to re-binding the state to a different backend, taken at the next plan. |
force_unlock |
Release a stale state lock now, as tofu force-unlock. Only on the user’s explicit yes. |
lock_id |
The lock to release, as the error names it; implies force_unlock. |
list and delete take config_alias and the backend settings as open does, plus var and
var_file for this call only (for a backend block or state encryption that reads a variable).
delete also takes workspace_name (never default) and force. close takes workspace_alias;
status takes nothing.
Related
Section titled “Related”- Variables and var files
- Where credentials are read
- When something goes wrong: picking up a run, locks.
- Tear down with destroy
Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.
© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub