You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/terraform-docs-common/docs/cloud-docs/migrate/index.mdx
+24-11Lines changed: 24 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ description: >-
6
6
7
7
# Migrate Terraform state to HCP Terraform or Terraform Enterprise
8
8
9
-
This topic describes how to migrate existing Terraform state files to HCP Terraform or Terraform Enterprise without first de-provisioning them. Refer to [State](/terraform/language/state) in the Terraform configuration language reference for additional information about Terraform state.
9
+
This topic describes how to migrate existing Terraform state files to HCP Terraform or Terraform Enterprise without first de-provisioning them. Refer to [State](/terraform/language/state) in the Terraform configuration language reference for additional information about Terraform state.
10
10
11
11
## Overview
12
12
13
13
Perform the following actions to migrate existing resources to one or more workspaces in HCP Terraform or Terraform Enterprise:
14
14
15
-
1. Stop all Terraform operations associated with the state files.
15
+
1. Stop all Terraform operations associated with the state files.
16
16
1. Migrate Terraform state files to HCP Terraform or Terraform Enterprise.
17
17
18
18
You have three options to migrate your state:
@@ -39,9 +39,9 @@ Stop all Terraform operations associated with the state files. This may require
39
39
40
40
41
41
1. Add the `cloud` block to your Terraform configuration and specify the following fields:
42
-
1.`hostname` field: Specify either `app.terraform.io` for HCP Terraform or the hostname of your Terraform Enterprise deployment.
43
-
1.`organization` field: Specify your HCP Terraform or Terraform Enterprise organization.
44
-
1.`workspaces` block: Add a `tags` or `name` field and specify one or more destination workspaces as a list of strings.
42
+
1.`hostname` field: Specify either `app.terraform.io` for HCP Terraform or the hostname of your Terraform Enterprise deployment.
43
+
1.`organization` field: Specify your HCP Terraform or Terraform Enterprise organization.
44
+
1.`workspaces` block: Add a `tags` or `name` field and specify one or more destination workspaces as a list of strings.
45
45
46
46
Refer to [The `cloud` Block](/terraform/cli/cloud/settings#the-cloud-block) in the Terraform CLI documentation for additional information. The following example migrates the state associated with the configuration to the `networking` workspace on HCP Terraform:
47
47
@@ -69,17 +69,17 @@ Stop all Terraform operations associated with the state files. This may require
1. If the workspace does not yet exist in your organization, send a `POST` request to the `/organizations/:organization_name/workspaces` endpoint to create it. Otherwise, proceed to the next step. Refer to the following topics for details:
74
-
-[Create a workspace](/terraform/cloud-docs/api-docs/workspaces#create-a-workspace) in the HCP Terraform API reference documentation.
74
+
-[Create a workspace](/terraform/cloud-docs/api-docs/workspaces#create-a-workspace) in the HCP Terraform API reference documentation.
75
75
-[Create a workspace](/terraform/enterprise/api-docs/workspaces#create-a-workspace) in the Terraform Enterprise API reference documentation.
76
76
1. Send a `POST` request to the `/workspaces/:workspace_id/actions/lock` endpoint to lock the workspace. Refer to the following topics for details:
77
-
-[Lock a workspace](/terraform/cloud-docs/api-docs/workspaces#lock-a-workspace) in the HCP Terraform API reference documentation.
78
-
-[Lock a workspace](/terraform/enterprise/api-docs/workspaces#lock-a-workspace) in the Terraform Enterprise API reference documentation.
77
+
-[Lock a workspace](/terraform/cloud-docs/api-docs/workspaces#lock-a-workspace) in the HCP Terraform API reference documentation.
78
+
-[Lock a workspace](/terraform/enterprise/api-docs/workspaces#lock-a-workspace) in the Terraform Enterprise API reference documentation.
79
79
1. To upload your state files to the workspace, send a `POST` request to the `/workspaces/:workspace_id/state-versions` endpoint. Specify the MD5 string in the `data.attributes.md5` field and encoded state file in the `data.attributes.state` field of the request body. Refer to the following topics for details:
80
-
-[Create a state version](/terraform/cloud-docs/api-docs/state-versions#create-a-state-version) in the HCP Terraform API reference documentation.
80
+
-[Create a state version](/terraform/cloud-docs/api-docs/state-versions#create-a-state-version) in the HCP Terraform API reference documentation.
81
81
-[Create a state version](/terraform/enterprise/api-docs/state-versions#create-a-state-version) in the Terraform Enterprise API reference documentation.
82
-
1. Send a `POST` request to the `/workspaces/:workspace_id/actions/unlock` endpoint to unlock the workspace.
82
+
1. Send a `POST` request to the `/workspaces/:workspace_id/actions/unlock` endpoint to unlock the workspace.
83
83
84
84
Refer to the following external article for an example of how to create a script in Python to automate multiple state files:
85
85
[Migrating A Lot of State with Python and the HCP Terraform (previously Terraform Cloud) API](https://medium.com/hashicorp-engineering/migrating-a-lot-of-state-with-python-and-the-terraform-cloud-api-997ec798cd11). The example uses the [Workspaces API](/terraform/cloud-docs/api-docs/workspaces#create-a-workspace) to create the necessary workspaces in HCP Terraform and the [State Versions API](/terraform/cloud-docs/api-docs/state-versions) to migrate the state files to those workspaces.
@@ -90,3 +90,16 @@ Refer to the following external article for an example of how to create a script
90
90
> **Hands-on:** Complete the [Migrate to HCP Terraform in bulk](/terraform/tutorials/cloud/bulk-migrate-hcp) tutorial to get started with tf-migrate.
91
91
92
92
You can use the `tf-migrate` CLI tool to automatically migrate state to HCP Terraform and Terraform Enterprise. The tool does not ship with HCP Terraform. You must download and install the binary for the CLI tool separately. Refer to the [`tf-migrate` documentation](/terraform/migrate) for more information.
Copy file name to clipboardExpand all lines: content/terraform-docs-common/docs/cloud-docs/stack-workspace.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ Workspaces provide a hard separation between environments because each workspace
28
28
29
29
If your team uses a branching strategy where each environment maps to a separate Git branch, workspaces can align with your workflow. You can promote changes across environments through pull requests between branches. Workspaces also work well when CI/CD pipelines control promotion across environments, especially when a promotion must be gated by approvals or automated test outcomes.
30
30
31
-
Previously, those looking to deploy repeatable infrastructure using HCP Terraform would create separate workspaces and then use run triggers or other automation tools to coordinate changes between them. However, workspaces are not truly coupled to each other, hampering your ability to flexibly manage infrastructure as it scales. If you have a tightly orchestrated infrastructure that changes across different environments, we recommend defining a Stack.
31
+
Previously, those looking to deploy repeatable infrastructure using HCP Terraform would create separate workspaces and then use run triggers or other automation tools to coordinate changes between them. However, workspaces are not truly coupled to each other, hampering your ability to flexibly manage infrastructure as it scales. If you have a tightly orchestrated infrastructure that changes across different environments, we recommend defining a Stack. If you want to migrate an existing workspace to a Stack, refer to the [Terraform migrate CLI](/terraform/migrate/stacks).
32
32
33
33
Workspaces do support validating your code with policies, drift detection, and a range of other features that Stacks do not support. Refer to [Feature support](#feature-support) to learn more.
34
34
@@ -45,7 +45,7 @@ We recommend using Stacks if your use case meets any of the following conditions
45
45
- You repeat infrastructure across different environments, regions, or accounts that require consistent and synchronized deployments.
46
46
- You have a tightly orchestrated infrastructure that changes across different environments.
47
47
48
-
Stacks codify the entire behavior of your infrastructure lifecycle within version-controlled configuration files. To learn more about Stacks and review examples, refer to [Stack use cases](/terraform/language/stacks/use-cases).
48
+
Stacks codify the entire behavior of your infrastructure lifecycle within version-controlled configuration files. To learn more about Stacks and review examples, refer to [Stack use cases](/terraform/language/stacks/use-cases). If you want to migrate an existing workspace to a Stack, refer to the [Terraform migrate CLI](/terraform/migrate/stacks).
49
49
50
50
Stacks were designed to simplify and scale Terraform workflows that become complex or repetitive using workspaces. When you use a Stack, HCP Terraform automatically recognizes the dependency between components, automatically deferring the component's plan and apply steps until it can complete them successfully. Learn more about how Stacks plan [deferred changes](/terraform/cloud-docs/stacks/deploy/runs#deferred-changes).
Copy file name to clipboardExpand all lines: content/terraform-docs-common/docs/cloud-docs/stacks/create.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,8 @@ You can create a Stack using any of the following methods:
31
31
- The HCP Terraform UI
32
32
- The Terraform CLI
33
33
34
+
If you want to migrate an existing workspace to a Stack, refer to the [Terraform migrate CLI](/terraform/migrate/stacks).
35
+
34
36
If you are creating a Stack in an organization for the first time, you must enable Stacks for your organization. Navigate to your organization’s **Settings** page, and in the **General** settings, check the box next to **Stacks**.
Copy file name to clipboardExpand all lines: content/terraform/v1.13.x/docs/language/block/stack/tfdeploy/deployment.mdx
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,7 +156,7 @@ We recommend using the `destroy` argument to remove deployments to ensure your c
156
156
157
157
### `import`
158
158
159
-
The `import` argument is a placeholder for future functionality.
159
+
The `tf-migrate` CLI can migrate the state of an existing HCP Terraform workspace to a Stack deployment. The `tf-migrate` CLI automatically sets the `import` argument to `true` when importing the state of an existing workspace to a specific deployment.
160
160
161
161
```hcl
162
162
deployment "<LABEL>" {
@@ -168,6 +168,10 @@ deployment "<LABEL>" {
168
168
}
169
169
```
170
170
171
+
Terraform migrate sets the `import` argument to let HCP Terraform know that the rest of the deployments in a Stack can continue plan as normal while the deployment with `import` is migrating state.
172
+
173
+
To learn more about migrating a workspace to a Stack deployment, refer to [Terraform migrate](/terraform/migrate/stacks).
Copy file name to clipboardExpand all lines: content/terraform/v1.14.x (beta)/docs/language/block/stack/tfdeploy/deployment.mdx
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,7 +155,7 @@ We recommend using the `destroy` argument to remove deployments to ensure your c
155
155
156
156
### `import`
157
157
158
-
The `import` argument is a placeholder for future functionality.
158
+
The `tf-migrate` CLI can migrate the state of an existing HCP Terraform workspace to a Stack deployment. The `tf-migrate` CLI automatically sets the `import` argument to `true` when importing the state of an existing workspace to a specific deployment.
159
159
160
160
```hcl
161
161
deployment "<LABEL>" {
@@ -167,6 +167,10 @@ deployment "<LABEL>" {
167
167
}
168
168
```
169
169
170
+
Terraform migrate sets the `import` argument to let HCP Terraform know that the rest of the deployments in a Stack can continue plan as normal while the deployment with `import` is migrating state.
171
+
172
+
To learn more about migrating a workspace to a Stack deployment, refer to [Terraform migrate](/terraform/migrate/stacks).
0 commit comments