Terraform State Migration Guide
This guide provides a detailed, step-by-step process for migrating the Terraform state into Bluebricks. By following these instructions, you'll ensure a seamless and hassle-free migration of the old infrastructure state into Bluebricks managed state.
Migration Steps
Before beginning the migration, confirm the following:
Migration Workflow
Prepare the Current Terraform Environment
Open the terminal and navigate to the folder that contains the code to be migrated.
cd ~/path/to/terraformInitialize the Terraform Directory
terraform initValidate Current State
terraform planEnsures no pending changes exist in the current configuration. An exit code of 0 indicates no modifications are required.
Removes the
.terraformdirectory to facilitate a fresh initialization
rm -rf .terraformPrepare State File for Migration
Exports the entire Terraform state file to a local JSON file for reference
terraform state pull > terraform.jsonCreate a new
terraform.tfstatefile and copy the resources that match the module to be migrated fromterraform.json.
Migrating multiple resources of the same type/package is not supported.
Validate the created
terraform.tfstatefile by running the following command:
terraform planConfirm the output shows no planned changes.
Validate the syntax of the state
terraform show -json terraform.tfstateAfter copying and validation are complete, remove the
terraform.jsonfile
rm terraform.jsonConvert Module to an Artifact
Navigate to the parent folder
cd ..Create an Artifact by running the following command:
bricks bp prepare --source=./terraform --output=./artifact --bricks-onlyChange directory to
artifactand publish the created Artifact
bricks bp publish --stateValidate Artifact
Test Artifact by initiate a plan-only installation
bricks install <package_name> --plan-onlyCleanup Artifact
Remove temporary files
Delete the migrated
terraform.tfstatefileRemove
state_pathentry frombricks.json
Finalize Deployment
Increment Artifact version
bricks bp bumpPublish final changes
bricks bp publishLast updated
Was this helpful?

