Terraform
- Terraform Enterprise
- 1.0.x (latest)
- v202507-1
- v202506-1
- v202505-1
- v202504-1
- v202503-1
- v202502-2
- v202502-1
- v202411-2
- v202411-1
- v202410-1
- v202409-3
- v202409-2
- v202409-1
- v202408-1
- No versions of this document exist before v202408-1. Click below to redirect to the version homepage.
- v202407-1
- v202406-1
- v202405-1
- v202404-2
- v202404-1
- v202402-2
- v202402-1
- v202401-2
- v202401-1
- v202312-1
- v202311-1
- v202310-1
- v202309-1
- v202308-1
- v202307-1
- v202306-1
- v202305-2
- v202305-1
- v202304-1
- v202303-1
- v202302-1
- v202301-2
- v202301-1
- v202212-2
- v202212-1
- v202211-1
- v202210-1
- v202209-2
- v202209-1
- v202208-3
- v202208-2
- v202208-1
- v202207-2
- v202207-1
- v202206-1
Install Terraform migrate
Terraform migrate automatically migrates your Terraform Community Edition state to HCP Terraform or Terraform Enterprise. It also updates your local configuration with any necessary changes and optionally creates a pull request to update your code repository.
Overview
Complete the following steps to migrate Terraform state using the CLI:
- Download and install - tf-migrate: You can manually download and install or use Homebrew if you are on macOS.
- tf-migrate prepare: This step scans the current working directory and generates Terraform configuration to migrate your state. The generated migration plan depends on the structure of your configuration. For more information, refer to tf-migrate prepare.
- tf-migrate execute: This step directs Terraform to run the- init,- plan, and- applycommands to perform the migration to HCP Terraform or Terraform Enterprise. At the end of the migration,- tf-migratedisplays a summary of what it migrated, links to the workspaces it created, and, if configured, a link to the pull request it created. For more information, refer to tf-migrate execute.
Install
HashiCorp distributes Terraform migrate as a binary package. To install Terraform migrate, find the appropriate binary for your operating system and download it as a zip archive.
After you download Terraform migrate, unzip the archive. Terraform migrate runs as a single binary named tf-migrate.
Finally, make sure that the tf-migrate binary is available in a directory that is in your system's PATH. 
Verify the installation
Every build of Terraform migrate includes a SHA256SUMS and a SHA256SUMS.sig file to validate your downloaded binary. Refer to the verify HashiCorp binary downloads tutorial for more information.
Authentication
Terraform migrate uses your locally configured Terraform CLI API token. If you have not authenticated your local Terraform installation with HCP Terraform, use the terraform login command to create an authentication token.
$ terraform login
 
Terraform will request an API token for app.terraform.io using your browser.
 
If login is successful, Terraform will store the token in plain text in
the following file for use by subsequent commands:
   /Users/redacted/.terraform.d/credentials.tfrc.json
 
Do you want to proceed?
 Only 'yes' will be accepted to confirm.
 
 Enter a value: yes
Terraform opens a browser to the HCP Terraform login screen. Enter a token name in the web UI, or leave the default name. Click Create API token to generate the authentication token.
HCP Terraform only displays your token once. Copy this token, then when the Terraform CLI prompts you, paste the user token exactly once into your terminal. Press Enter to complete the authentication process.
Terraform migrate uses the GitHub API to create a pull request to update your configuration. Set the GITHUB_TOKEN environment variable to provide your GitHub API token. Your token must have the repo scope.
$ export GITHUB_TOKEN=<TOKEN>
Logging
You can enable detailed logging by setting the TF_MIGRATE_ENABLE_LOG environment variable to true. When you enable this setting, Terraform migrate writes the logs to the following locations, depending on your operating system:
| Platform | Location | 
|---|---|
| macOS/Linux | /Users/<username>/.tf-migrate/logs/<commandName>/<date>.log | 
| Windows | C:\Users\<username>\.tf-migrate\logs\<commandName>\<date>.log | 
You can set the TF_MIGRATE_LOG_LEVEL environment variable to one of the following values to change the verbosity of the logs (in order of decreasing verbosity):