Skip to content

Commit 1022f64

Browse files
authored
Merge pull request #431 from hashicorp/RK/migrate-for-the-future
2 parents 374dff1 + d8dfd25 commit 1022f64

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

content/terraform-docs-common/docs/cloud-docs/migrate/index.mdx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ description: >-
66

77
# Migrate Terraform state to HCP Terraform or Terraform Enterprise
88

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.
1010

1111
## Overview
1212

1313
Perform the following actions to migrate existing resources to one or more workspaces in HCP Terraform or Terraform Enterprise:
1414

15-
1. Stop all Terraform operations associated with the state files.
15+
1. Stop all Terraform operations associated with the state files.
1616
1. Migrate Terraform state files to HCP Terraform or Terraform Enterprise.
1717

1818
You have three options to migrate your state:
@@ -39,9 +39,9 @@ Stop all Terraform operations associated with the state files. This may require
3939
4040

4141
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.
4545

4646
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:
4747

@@ -69,17 +69,17 @@ Stop all Terraform operations associated with the state files. This may require
6969
$ md5sum terraform.tfstate
7070
690a3f8ae079c629494a52c68757d585 terraform.tfstate
7171
```
72-
72+
7373
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.
7575
- [Create a workspace](/terraform/enterprise/api-docs/workspaces#create-a-workspace) in the Terraform Enterprise API reference documentation.
7676
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.
7979
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.
8181
- [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.
8383

8484
Refer to the following external article for an example of how to create a script in Python to automate multiple state files:
8585
[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
9090
> **Hands-on:** Complete the [Migrate to HCP Terraform in bulk](/terraform/tutorials/cloud/bulk-migrate-hcp) tutorial to get started with tf-migrate.
9191
9292
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.
93+
94+
<!-- BEGIN: TFC:only name:stacks-tfe -->
95+
96+
## Migrate a workspace to a Stack
97+
98+
In HCP Terraform, there are two ways of organizing your infrastructure:
99+
100+
- Workspaces are ideal for managing a self-contained infrastructure of one Terraform root module.
101+
- Stacks are ideal for managing multiple infrastructure modules and repeating that infrastructure at scale.
102+
103+
If you have an existing workspace that you want to convert to a Stack, you can use the Terraform migrate CLI to migrate your workspace state and configuration to a Stack in HCP Terraform. Refer to the [Terraform migrate CLI](/terraform/migrate/stacks) to learn more.
104+
105+
<!-- END: TFC:only name:stacks-tfe -->

content/terraform-docs-common/docs/cloud-docs/stack-workspace.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Workspaces provide a hard separation between environments because each workspace
2828

2929
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.
3030

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).
3232

3333
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.
3434

@@ -45,7 +45,7 @@ We recommend using Stacks if your use case meets any of the following conditions
4545
- You repeat infrastructure across different environments, regions, or accounts that require consistent and synchronized deployments.
4646
- You have a tightly orchestrated infrastructure that changes across different environments.
4747

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).
4949

5050
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).
5151

content/terraform-docs-common/docs/cloud-docs/stacks/create.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ You can create a Stack using any of the following methods:
3131
- The HCP Terraform UI
3232
- The Terraform CLI
3333

34+
If you want to migrate an existing workspace to a Stack, refer to the [Terraform migrate CLI](/terraform/migrate/stacks).
35+
3436
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**.
3537

3638
### HCP Terraform workflow

content/terraform/v1.13.x/docs/language/block/stack/tfdeploy/deployment.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ We recommend using the `destroy` argument to remove deployments to ensure your c
156156

157157
### `import`
158158

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.
160160

161161
```hcl
162162
deployment "<LABEL>" {
@@ -168,6 +168,10 @@ deployment "<LABEL>" {
168168
}
169169
```
170170

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).
174+
171175
#### Summary
172176

173177
- Data type: Boolean

content/terraform/v1.14.x (beta)/docs/language/block/stack/tfdeploy/deployment.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ We recommend using the `destroy` argument to remove deployments to ensure your c
155155

156156
### `import`
157157

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.
159159

160160
```hcl
161161
deployment "<LABEL>" {
@@ -167,6 +167,10 @@ deployment "<LABEL>" {
167167
}
168168
```
169169

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).
173+
170174
#### Summary
171175

172176
- Data type: Boolean

0 commit comments

Comments
 (0)