The persistent data stored in the backend belongs to a workspace.
Certain backends support multiple named workspaces, allowing multiple states
to be associated with a single configuration.
Terraform starts with a single workspace named "default". This
workspace is special both because it is the default and also because
it cannot ever be deleted.
Within your Terraform configuration, you may include the name of the current
workspace using the ${terraform.workspace} interpolation sequence.
changing behavior based
on the workspace.
Named workspaces allow conveniently switching between multiple instances of
a single configuration within its single backend.
A common use for multiple workspaces is to create a parallel, distinct copy of
a set of infrastructure in order to test a set of changes before modifying the
main production infrastructure.
Non-default workspaces are often related to feature branches in version control.
Workspaces alone
are not a suitable tool for system decomposition, because each subsystem should
have its own separate configuration and backend, and will thus have its own
distinct set of workspaces.
In particular, organizations commonly want to create a strong separation
between multiple deployments of the same infrastructure serving different
development stages (e.g. staging vs. production) or different internal teams.
use one or more re-usable modules to
represent the common elements, and then represent each instance as a separate
configuration that instantiates those common elements in the context of a
different backend.
If a Terraform state for one configuration is stored in a remote backend
that is accessible to other configurations then
terraform_remote_state
can be used to directly consume its root module outputs from those other
configurations.
For server addresses, use a provider-specific resource to create a DNS
record with a predictable name and then either use that name directly or
use the dns provider to retrieve
the published addresses in other configurations.
Workspaces are technically equivalent to renaming your state file.
using a remote backend instead is recommended when there are
multiple collaborators.