Terraform
tf-migrate prepare
The tf-migrate prepare
command recursively scans the current directory for Terraform state files, then generates new Terraform configuration to migrate the state to HCP Terraform or Terraform Enterprise.
Usage
$ tf-migrate prepare [options]
Description
The tf-migrate prepare
command prompts you for the following information:
- The HCP Terraform or Terraform Enterprise organization to migrate your state to.
- If you would like to create a new branch named
hcp-migrate-main
. - If you would like it to automatically create a pull request with the updated code change when the migration is complete.
After you run the prepare
command, Terraform migrate generates a new Terraform configuration in the hcp-migrate-config
directory to perform the migration. This configuration creates the following resources:
- One workspace per state file
- One project to store all workspaces
- A new local git branch if you responded to the prompt to create a new branch with
yes
. - A new pull request in the remote git repository if you responded to the prompt to create a pull request with
yes
.
The tf-migrate
CLI tool adds the generated configuration to the .gitignore
file so that the configuration is not committed to source control.
Terraform migrate creates the following structure in HCP Terraform or Terraform Enterprise depending on your local configuration:
Source | Result |
---|---|
Single configuration, single state | Single HCP workspace |
Single configuration, multiple states for each Community Edition workspace | One HCP workspace per state |
Multiple configurations, one state per configuration | One HCP workspace per configuration |
Multiple configurations, multiple states per configuration | One HCP workspace per combination of configuration and state |
Example
The following configuration uses the AWS S3 backend and has a single state file.
.
├── LICENSE
├── README.md
└── main.tf
The tf-migrate prepare
command generates the configuration to migrate this state to a single HCP Terraform workspace.
$ tf-migrate prepare
✓ Current working directory: /tmp/backend-test/learn-terraform-migrate
✓ Environment readiness checks completed
✓ Found 3 HCP Terraform organizations
┌────────────────────────────┐
│ Available Orgs │
├────────────────────────────┤
│ my-org-1 │
│ my-org-2 │
│ my-org-3 │
└────────────────────────────┘
Enter the name of the HCP Terraform organization to migrate to: my-org-1
✓ You have selected organization my-org-1 for migration
✓ Found 1 directories with Terraform files
┌────────────────────────────────┐
│ Terraform File Directories │
├────────────────────────────────┤
│ learn-terraform-migrate │
└────────────────────────────────┘
Create a local branch named hcp-migrate-main from the current branch main: ... ?
Only 'yes or no' will be accepted as input.
Type 'yes' to approve the step
Type 'no' to to skip
Enter a value: yes
✓ Successfully created branch hcp-migrate-main
Do you want to open a pull request from hcp-migrate-main ... ?
Only 'yes or no' will be accepted as input.
Type 'yes' to approve the step
Type 'no' to to skip
Enter a value: yes
✓ Migration config generation completed
Available options
You can include the following flags when you run the tf-migrate prepare
command:
Option | Description | Default | Required |
---|---|---|---|
-hostname | The hostname of your Terraform Enterprise server. If you do not provide a hostname, Terraform migrate defaults to HCP Terraform. | app.terraform.io | No |