- The OpenTofu Language
- OpenTofu Settings
- Backends
- remote
Backend Type: remote
We recommend using the cloud built-in integration instead of this backend. The cloud option includes an improved user experience and more features.
The remote backend is unique among all other OpenTofu backends because it can both store state snapshots and execute CLI-driven run workflow operations for TF Automation and Collaboration Software (TACOS) backends. It used to be called an "enhanced" backend.
If your TACOS provider enables full remote operations, you can execute commands such as tofu plan or tofu apply within the TACOS runtime environment, with log output streaming directly to your local terminal. Remote plans and applies use variable values from the associated remote workspace.
You can also use TACOS with local operations, where only state is stored in the TACOS remote backend.
Command Support​
Features implementation might vary between different TACOS.
The remote backend supports the following OpenTofu commands:
applyconsoledestroyfmtgetgraphimportinitoutputplanprovidersshowstate(supports all sub-commands: list, mv, pull, push, rm, show)taintuntaintvalidateversionworkspace
Workspaces​
The remote backend can work with either a single remote workspace, or with multiple similarly-named remote workspaces (like networking-dev and networking-prod). The workspaces block of the backend configuration
determines which mode it uses:
-
To use a single remote workspace, set
workspaces.nameto the remote workspace's full name (likenetworking-prod). -
To use multiple remote workspaces, set
workspaces.prefixto a prefix used in all of the desired remote workspace names. For example, setprefix = "networking-"to use remote workspaces with names likenetworking-devandnetworking-prod. This is helpful when mapping multiple OpenTofu CLI workspaces used in a single OpenTofu configuration to multiple remote workspaces.
The backend configuration requires either name or prefix. Omitting both or
setting both results in a configuration error.
If previous state is present when you run tofu init and the corresponding
remote workspaces are empty or absent, OpenTofu will create workspaces and
update the remote state accordingly. However, if your workspace requires variables or a specific version of OpenTofu for remote operations, we
recommend that you create your remote workspaces on TACOS before
running any remote operations against them.
Workspace Names​
OpenTofu uses shortened names without the common prefix to interact with workspaces on the command line. For example, if prefix = "networking-", use tofu workspace select prod to switch to the OpenTofu CLI workspace prod within the current configuration. However, remote OpenTofu operations such as plan and apply for that OpenTofu CLI workspace will take place in the remote workspace networking-prod.
Because of this, the terraform.workspace interpolation expression produces different results depending on whether a remote workspace is configured to perform operations locally or remotely. For example, in a remote workspace called networking-prod created with prefix = "networking-" the expression produces the following:
- For local operations,
terraform.workspace=Âprod - For remote operations,
terraform.workspace=networking-prod
Example Configurations​
We recommend omitting the token from the configuration, and instead using
tofu login or manually configuring
credentials in the CLI config file.
Basic Configuration​
# Using a single workspace:
terraform {
backend "remote" {
hostname = "app.example.io"
organization = "company"
workspaces {
name = "my-app-prod"
}
}
}
# Using multiple workspaces:
terraform {
backend "remote" {
hostname = "app.example.io"
organization = "company"
workspaces {
prefix = "my-app-"
}
}
}