Terraform
The tf-migrate modules create command moves all resources in the root module into a new child module so that you can deploy it as a Stack.
Usage
$ tf-migrate modules create [options]
Description
The tf-migrate modules create command wraps your root module into a child module so that you can deploy it as a Stack. This command does not modify your state, instead it makes a copy of your configuration in a directory named modularized_config. Ensure that a directory named modularized_config does not exist in the current directory before you run this command.
Example
The following example makes a copy of the configuration in the modularized_config subdirectory and converts the root module into a child module.
$ tf-migrate modules create
✓ Found 1 terraform files in the root directory
✓ Extracted HCP Terraform data to identify the workspaces controlled by the configuration.
You're about to begin the modularization process.
Please read the following important notes carefully:
1. A folder named "modularized_config" will be created to store the new modularized
configuration generated from your current setup.
2. All directories containing locally referenced modules will be copied into the
"modularized_config" folder.
3. The "modularized_config" folder must not already exist in the current working directory.
4. All required providers must be referenced exclusively from a variable block
5. All folders for locally referenced modules must be located within the current working
directory where tf-migrate is being run.
Confirmation required ... ?
Only 'yes' or 'no' will be accepted as input.
Type 'yes' to approve proceed with the modularization process.
Type 'no' to cancel and abort.
Enter a value: yes
✓ Found 2 HCP Terraform workspaces associated with the configuration.
✓ Deleted backend block cloud from terraform block during modularization
✓ Successfully generated modularized configuration in modularized_config directory
✓ Modularization process completed successfully
Your modularized configuration files are available in the "modularized_config" directory.
Next steps to migrate your workspaces to Terraform Stacks:
1. Change into the modularized configuration directory:
cd modularized_config
2. Copy any .tfvars files (from the top-level directories)
3. Initialize Terraform:
terraform init
4. Prepare the stack migration:
tf-migrate stacks prepare
Available options
You can include the following flags when you run the tf-migrate modules create command:
| Option | Description | Default | Required |
|---|---|---|---|
-config-file | Specifies the path to an optional configuration file. Refer to tf-migrate configuration file reference for more information. | None | No |
Troubleshooting
If your Terraform configuration references external files, such as scripts, or local modules outside of the current working directory, tf-migrate does not automatically include these files automatically. After you run this command, review the modularized_config/terraform_modules directory to verify that it contains all files required to deploy your configuration.