github.com/hugorut/terraform@v1.1.3/website/docs/cli/cloud/migrating.mdx (about) 1 --- 2 page_title: Initializing and Migrating to Terraform Cloud - Terraform CLI 3 --- 4 5 # Initializing and Migrating 6 7 After [configuring Terraform Cloud settings](/cli/cloud/settings) for a working directory, you must run `terraform init` to finish setting up. If the working directory has no existing Terraform state, you can start using Terraform with Terraform Cloud right away. Refer to [CLI-driven run workflow](/cloud-docs/run/cli) for more details. 8 9 When you run `terraform init` in the following scenarios, Terraform will ask you to choose whether or not to migrate state from any existing workspaces. 10 11 1. [**Migrating from local state or state backends:**](#migrating-from-local-state-or-state-backends) If the working directory already has state data in one or more workspaces, Terraform will ask if you would like to migrate that state to new Terraform Cloud workspaces. 12 13 1. [**Migrating from the `remote` backend:**](#migrating-from-the-remote-backend) If the working directory was already connected to Terraform Cloud with the `remote` backend, Terraform can continue using the same Terraform Cloud workspaces. You will need to switch the `remote` backend block to the `cloud` block. 14 15 ## Migrating from Local State or State Backends 16 17 > **Hands On:** Try the [Migrate State to Terraform Cloud](https://learn.hashicorp.com/tutorials/terraform/cloud-migrate) tutorial on HashiCorp Learn. 18 19 If the working directory already has state data available (using either local state or a [state 20 backend](/language/settings/backends)), Terraform will ask your approval to migrate 21 that state to Terraform Cloud. You will need permission to manage workspaces in the destination Terraform Cloud organization. This process is interactive and self-documenting, and resembles 22 moving between state backends. 23 24 Terraform may also prompt you to rename your workspaces during the migration, to either give a name to 25 the unnamed `default` workspace (Terraform Cloud requires all workspaces to have a name) or give 26 your workspace names more contextual information. Unlike Terraform CLI-only workspaces, which represent 27 multiple environments associated with the same configuration (e.g. production, staging, development), 28 Terraform Cloud workspaces can represent totally independent configurations, and must have unique names within the Terraform Cloud organization. 29 30 Because of this, Terraform will prompt you to rename the working directory's workspaces 31 according to a pattern relative to their existing names. This can indicate the fact that these specific workspaces share configuration. A typical strategy is 32 `<COMPONENT>-<ENVIRONMENT>-<REGION>` (e.g., `networking-prod-us-east`, 33 `networking-staging-us-east`). Refer to [Workspace 34 Naming](/cloud-docs/workspaces/naming) in the Terraform Cloud documentation for more detail. 35 36 ## Migrating from the `remote` Backend 37 38 If the working directory was already connected to Terraform Cloud with the `remote` backend, Terraform can continue using the same Terraform Cloud workspaces. The local names shown for those workspaces will change to match their remote names. 39 40 The [`remote` backend](/language/settings/backends/remote) was the primary implementation of Terraform Cloud's [CLI-driven run workflow](/cloud-docs/run/cli) for Terraform versions 0.11.13 through 1.0.x. We recommend using the native `cloud` integration for Terraform versions 1.1 or later, as it provides an improved user experience and various enhancements. 41 42 ### Block Replacement 43 44 When switching from the `remote` backend to a `cloud` block, Terraform will continue using the same 45 set of Terraform Cloud workspaces. Replace your `backend "remote"` block with an equivalent `cloud` 46 block. 47 48 #### Single Workspace 49 50 If you were using a single workspace with the `name` argument, change the block 51 label to `cloud`. 52 53 ```diff 54 terraform { 55 - backend "remote" { 56 + cloud { 57 organization = "my-org" 58 59 workspaces { 60 name = "my-app-prod" 61 } 62 } 63 } 64 ``` 65 66 #### Multiple Workspaces 67 68 If you were using multiple workspaces with the `prefix` argument, replace it with a `cloud` block that uses the `tags` argument. You may specify any number of tags to distinguish the workspaces for your working directory, but a good starting point may be to use whatever the prefix was before. 69 70 The tags you configure do not need to be present on the existing workspaces. When you initialize, Terraform will add the specified tags to the workspaces if necessary. 71 72 ```diff 73 terraform { 74 - backend "remote" { 75 + cloud { 76 organization = "my-org" 77 78 workspaces { 79 - prefix = "my-app-" 80 + tags = ["app:mine"] 81 } 82 } 83 } 84 ```