github.com/hugorut/terraform@v1.1.3/website/docs/cli/workspaces/index.mdx (about)

     1  ---
     2  page_title: Managing Workspaces - Terraform CLI
     3  description: >-
     4    Commands to list, select, create, and output workspaces. Workspaces help
     5    manage different groups of resources with one configuration.
     6  ---
     7  
     8  # Managing Workspaces
     9  
    10  In Terraform CLI, _workspaces_ are separate instances of
    11  [state data](/language/state) that can be used from the same working
    12  directory. You can use workspaces to manage multiple non-overlapping groups of
    13  resources with the same configuration.
    14  
    15  - Every [initialized working directory](/cli/init) has at least
    16    one workspace. (If you haven't created other workspaces, it is a workspace
    17    named `default`.)
    18  - For a given working directory, only one workspace can be _selected_ at a time.
    19  - Most Terraform commands (including [provisioning](/cli/run)
    20    and [state manipulation](/cli/state) commands) only interact
    21    with the currently selected workspace.
    22  - Use [the `terraform workspace select` command](/cli/commands/workspace/select)
    23    to change the currently selected workspace.
    24  - Use the [`terraform workspace list`](/cli/commands/workspace/list),
    25    [`terraform workspace new`](/cli/commands/workspace/new), and
    26    [`terraform workspace delete`](/cli/commands/workspace/delete) commands
    27    to manage the available workspaces in the current working directory.
    28  
    29  -> **Note:** Terraform Cloud and Terraform CLI both have features called
    30  "workspaces," but they're slightly different. Terraform Cloud's workspaces
    31  behave more like completely separate working directories.
    32  
    33  ## The Purpose of Workspaces
    34  
    35  Since most of the resources you can manage with Terraform don't include a unique
    36  name as part of their configuration, it's common to use the same Terraform
    37  configuration to provision multiple groups of similar resources.
    38  
    39  Terraform relies on [state](/language/state) to associate resources with
    40  real-world objects, so if you run the same configuration multiple times with
    41  completely separate state data, Terraform can manage many non-overlapping groups
    42  of resources. In some cases you'll want to change
    43  [variable values](/language/values/variables) for these different
    44  resource collections (like when specifying differences between staging and
    45  production deployments), and in other cases you might just want many instances
    46  of a particular infrastructure pattern.
    47  
    48  The simplest way to maintain multiple instances of a configuration with
    49  completely separate state data is to use multiple
    50  [working directories](/cli/init) (with different
    51  [backend](/language/settings/backends/configuration) configurations per directory, if you
    52  aren't using the default `local` backend).
    53  
    54  However, this isn't always the most _convenient_ way to handle separate states.
    55  Terraform installs a separate cache of plugins and modules for each working
    56  directory, so maintaining multiple directories can waste bandwidth and disk
    57  space. You must also update your configuration code from version control
    58  separately for each directory, reinitialize each directory separately when
    59  changing the configuration, etc.
    60  
    61  Workspaces allow you to use the same working copy of your configuration and the
    62  same plugin and module caches, while still keeping separate states for each
    63  collection of resources you manage.
    64  
    65  ## Interactions with Terraform Cloud Workspaces
    66  
    67  Terraform Cloud organizes infrastructure using workspaces, but its workspaces
    68  act more like completely separate working directories; each Terraform Cloud
    69  workspace has its own Terraform configuration, set of variable values, state
    70  data, run history, and settings.
    71  
    72  These two kinds of workspaces are different, but related. When [using Terraform
    73  CLI as a frontend for Terraform Cloud](/cli/cloud), you can associate the current working
    74  directory with one or more remote workspaces. If you associate the
    75  directory with multiple workspaces (using workspace tags), you can use the
    76  `terraform workspace` commands to select which remote workspace to use.
    77  
    78  Refer to [CLI-driven Runs](/cloud-docs/run/cli) in the Terraform Cloud documentation for more details about using Terraform CLI with Terraform Cloud.