Skip to content

Commit d45dc0b

Browse files
Add information about multi-workspace deployment with tf-migrate (#1270)
Co-authored-by: Robin Norwood <[email protected]>
1 parent f38c05c commit d45dc0b

File tree

6 files changed

+150
-65
lines changed

6 files changed

+150
-65
lines changed

content/terraform-migrate/v2.0.x/docs/migrate/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ If your local configuration does not meet all of the above requirements, `tf-mig
5252

5353
@include "stacks.mdx"
5454

55-
The `tf-migrate` CLI can migrate Terraform configuration and state from an HCP Terraform workspace to a Stack. Refer to [Migrate a workspace to a Stack](/terraform/migrate/stacks) for more information.
55+
The `tf-migrate` CLI can migrate Terraform configuration and state from one or more HCP Terraform workspaces to a Stack. Refer to [Migrate workspaces to a Stack](/terraform/migrate/stacks) for more information.
5656

5757
## Enable logging
5858

content/terraform-migrate/v2.0.x/docs/migrate/reference/cli/modules/create.mdx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,43 @@ The following example makes a copy of the configuration in the `modularized_conf
2828
$ tf-migrate modules create
2929
✓ Found 1 terraform files in the root directory
3030
✓ Extracted HCP Terraform data to identify the workspaces controlled by the configuration.
31+
You're about to begin the modularization process.
32+
Please read the following important notes carefully:
3133
32-
You're about to begin the modularization process. read the following important notes carefully:
33-
1. A folder named modularized_config will be created to store the modularized configuration generated from your current setup.
34-
2. All directories containing locally referenced modules will be copied into the modularized_config folder.
35-
3. The modularized_config folder must not already exist in the current working directory.
36-
4. All folders for locally referenced modules must be located within the current working directory where Terraform Migrate is being run.
34+
1. A folder named "modularized_config" will be created to store the new modularized
35+
configuration generated from your current setup.
36+
2. All directories containing locally referenced modules will be copied into the
37+
"modularized_config" folder.
38+
3. The "modularized_config" folder must not already exist in the current working directory.
39+
4. All required providers must be referenced exclusively from a variable block
40+
5. All folders for locally referenced modules must be located within the current working
41+
directory where tf-migrate is being run.
3742
38-
Kindly confirm that you have read and understood the warning message above. Do you want to proceed ... ?
43+
Confirmation required ... ?
3944
4045
4146
Only 'yes' or 'no' will be accepted as input.
42-
Type 'yes' to approve proceed with modularization process
43-
Type 'no' to abort the modularization process
47+
Type 'yes' to approve proceed with the modularization process.
48+
Type 'no' to cancel and abort.
4449
4550
4651
Enter a value: yes
4752
48-
✓ Found 1 HCP Terraform workspaces associated with the configuration.
49-
✓ Successfully generated modularized config in modularized_config
53+
✓ Found 2 HCP Terraform workspaces associated with the configuration.
54+
✓ Deleted backend block cloud from terraform block during modularization
55+
✓ Successfully generated modularized configuration in modularized_config directory
5056
✓ Modularization process completed successfully
57+
58+
Your modularized configuration files are available in the "modularized_config" directory.
59+
60+
Next steps to migrate your workspaces to Terraform Stacks:
61+
1. Change into the modularized configuration directory:
62+
cd modularized_config
63+
2. Copy any .tfvars files (from the top-level directories)
64+
3. Initialize Terraform:
65+
terraform init
66+
4. Prepare the stack migration:
67+
tf-migrate stacks prepare
5168
```
5269

5370
## Available options

content/terraform-migrate/v2.0.x/docs/migrate/reference/cli/stacks/cleanup.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ The example below uses the `tf-migrate stacks cleanup` command to delete a Stack
2828

2929
```
3030
$ tf-migrate stacks cleanup
31-
Please enter the Stack ID to delete: st-ab1CDefGHijKlmNo
32-
✓ Using provided stack ID: st-ab1CDefGHijKlmNo
33-
✓ Successfully deleted stack with ID: st-ab1CDefGHijKlmNo
31+
Please enter the Stack ID to delete: st-a1b2c3d4e5f6g7h8
32+
✓ Using provided stack ID: st-a1b2c3d4e5f6g7h8
33+
✓ Successfully deleted stack with ID: st-a1b2c3d4e5f6g7h8
3434
```
3535

3636
## Available options

content/terraform-migrate/v2.0.x/docs/migrate/reference/cli/stacks/execute.mdx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,34 @@ The `tf-migrate execute` command automatically performs the migration and code u
2828

2929
```
3030
$ tf-migrate stacks execute
31-
✓ Stack configuration path found: /tmp/random_mod/_stacks_generated
32-
✓ Successfully validated stack configuration found in dir: /tmp/random_mod/_stacks_generated
31+
✓ Stack configuration path found: /tmp/my-workspace/modularized_config/_stacks_generated
32+
✓ Successfully validated stack configuration found in dir: /tmp/my-workspace/modularized_config/_stacks_generated
33+
✓ Using dir: /tmp/my-workspace/modularized_config/stacks_migration_infra for terraform operations
3334
✓ Init command ran successfully
3435
✓ Plan command ran successfully and changes are detected
35-
✓ Apply command ran successfully in 35.049518291s
36+
✓ Apply command ran successfully in 55.73248925s
3637
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
3738
3839
3940
Migration Summary
40-
┌─────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────┐
41-
│ Item │ URL │
42-
├─────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────┤
43-
│ Project │ https://app.terraform.io/app/<ORG>/projects/prj-zcHA23BCD4EFGHij │
44-
│ Stack │ https://app.terraform.io/app/<ORG>/projects/prj-zcHA23BCD4EFGHij/stacks/st-ab1CDefGHijKlmNo │
45-
└─────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────┘
41+
┌─────────┬────────────────────────────────────────────────────────────────────────────────────────────────┐
42+
│ Item │ URL │
43+
├─────────┼────────────────────────────────────────────────────────────────────────────────────────────────┤
44+
│ Project │ https://app.terraform.io/app/<ORG>/projects/prj-a1b2c3d4e5f6g7h8 │
45+
│ Stack │ https://app.terraform.io/app/<ORG>/projects/prj-a1b2c3d4e5f6g7h8/stacks/st-a1b2c3d4e5f6g7h8 │
46+
└─────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘
47+
48+
Terraform Migrate has successfully executed the migration plan for your stack.
49+
Please verify the migration in the HCP Terraform UI.
50+
51+
Next Steps:
52+
1. Visit https://app.terraform.io/app/<ORG>/projects/prj-a1b2c3d4e5f6g7h8/stacks/st-a1b2c3d4e5f6g7h8.
53+
2. Review the uploaded configuration and confirm it has been applied successfully.
54+
3. Ensure all deployments under the stacks have completed. You may need to approve some plans.
55+
4. If you encounter issues, refer to the diagnostics in the UI and follow this troubleshooting guide:
56+
a. If there are configuration errors, review your stack configurations in _stacks_generated and resolve them.
57+
b. Delete the stack and project from the HCP Terraform UI if necessary.
58+
c. Remove the `.terraform` and `terraform.tfstate` files from the stacks_migration_infra directory on your local machine.
59+
d. Run `tf-migrate stacks execute` again to re-create the stacks and upload the corrected configuration.
60+
5. For post-migration guidance, see: https://developer.hashicorp.com/terraform/migrate/v2.0.x/stacks#next-steps
4661
```

content/terraform-migrate/v2.0.x/docs/migrate/reference/cli/stacks/prepare.mdx

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: >-
66

77
# `tf-migrate stacks prepare` reference
88

9-
The `tf-migrate stacks prepare` generates new Terraform configuration to migrate your HCP Terraform workspace to a Stack.
9+
The `tf-migrate stacks prepare` generates new Terraform configuration to migrate one or more HCP Terraform workspaces to a Stack.
1010

1111
@include "stacks.mdx"
1212

@@ -23,23 +23,60 @@ The `tf-migrate stacks prepare` command prompts you for the following informatio
2323
- A name for the Stack.
2424
- A name for the new project to deploy the Stack to. This project must not already exist.
2525

26-
The `tf-migrate prepare` command copies your configuration and local modules to create a new Terraform Stack configuration in the `_stacks_generated` directory. It also generated Terraform configuration to perform the migration in the `stacks_migration_infra` directory.
26+
The `tf-migrate prepare` command copies your configuration and local modules to create a new Terraform Stack configuration in the `_stacks_generated` directory. It also generates Terraform configuration to perform the migration in the `stacks_migration_infra` directory.
2727

28-
This command does not change your existing configuration.
28+
This command does not change your existing configuration, state, or deployed resources.
29+
30+
The `tf-migrate stacks prepare` command creates one Stack `deployment` block for each HCP Terraform workspace the configuration manages. If your configuration's `cloud` block targets a single workspace with the `workspaces.name` argument, `tf-migrate` creates one Stack deployment. If your configuration's `cloud` block targets multiple workspaces with the `workspaces.tags` argument, `tf-migrate` creates a Stack deployment for each workspace that matches those tags.
31+
32+
The following is an example is a `terraform` block that defines two tags, one named `environment` and another named `application`.
33+
34+
```hcl
35+
terraform {
36+
cloud {
37+
organization = "<ORG_NAME>"
38+
workspaces {
39+
tags = {
40+
"environment" = "development"
41+
"application" = "web"
42+
}
43+
}
44+
}
45+
}
46+
```
47+
48+
If this example matches two workspaces, `tf-migrate` creates two `deployment` blocks in the `_stacks_generated/deployment.tfdeploy.hcl` file and names them to match the workspace name.
49+
50+
```hcl
51+
deployment "web-dev-east" {
52+
inputs = {
53+
##...
54+
}
55+
import = true
56+
}
57+
58+
59+
60+
deployment "web-dev-west" {
61+
inputs = {
62+
##...
63+
}
64+
import = true
65+
}
66+
```
2967

3068
## Example
3169

3270
The `tf-migrate stacks prepare` command generates the configuration to migrate this HCP Terraform workspace to a Stack. The following example creates a Stack named `my-new-stack` in the `my-project` project.
3371

3472
```
3573
$ tf-migrate stacks prepare
36-
tf-migrate stacks prepare
3774
✓ Environment readiness checks completed
3875
✓ Extracted terraform configuration data from current directory
39-
Enter the name of the stack to be created: my-new-stack
40-
Enter the name of the project under which stack is to be created: my-project
41-
✓ Fetched latest state file for workspace: already-modular
42-
✓ Parsed state file for workspace: already-modular
76+
Enter the name of the stack to be created: my-stack
77+
Enter the name of a new project under which the stack will be created (project must not already exist): my-stack-proj
78+
✓ Fetched latest state file for workspace: my-workspace
79+
✓ Parsed state file for workspace: my-workspace
4380
✓ Extracted variables from terraform configuration
4481
✓ Extracted providers from terraform configuration
4582
✓ Extracted outputs blocks from terraform configuration
@@ -50,10 +87,25 @@ Enter the name of the project under which stack is to be created: my-project
5087
✓ Completed sanity check: terraform stacks fmt
5188
✓ Completed sanity check: terraform stacks validate
5289
53-
Please review the generated files in the stacks directory before proceeding to execute:
54-
1. Add stack authentication - https://developer.hashicorp.com/terraform/language/stacks/deploy/authenticate
55-
2. Resolve any PLACEHOLDER values for output block types, if any.
56-
3. Resolve any PLACEHOLDER values for deployment input attributes, if any.
90+
─────────────────────────────────────────────────────────────────────────────
91+
🎉 The `tf-migrate stacks prepare` command completed successfully.
92+
─────────────────────────────────────────────────────────────────────────────
93+
94+
Next steps:
95+
1. Review the generated files before proceeding:
96+
a. _stacks_generated — contains Terraform Stacks configuration files.
97+
b. stacks_migration_infra — contains Terraform configuration files for creating stacks and migrating workspaces.
98+
99+
2. Update all PLACEHOLDER values:
100+
- In output blocks (outputs.tfcomponent.hcl in _stacks_generated)
101+
- In deployment blocks (deployment.tfdeploy.hcl in _stacks_generated)
102+
103+
3. Configure authentication if your stacks manage cloud resources
104+
(AWS, GCP, Azure, etc.):
105+
→ https://developer.hashicorp.com/terraform/language/stacks/deploy/authenticate
106+
107+
4. Apply the configuration once all updates are complete:
108+
run: `tf-migrate stacks execute` to start the migration.
57109
```
58110

59111
## Available options

0 commit comments

Comments
 (0)