Migrate Terraform State to Bluebricks
How to migrate an existing Terraform deployment into Bluebricks when you want to adopt Bluebricks without recreating infrastructure
Use this guide when you have existing Terraform-managed infrastructure and want to bring it under Bluebricks management without destroying and recreating resources. You will publish your Terraform package, upload your existing state file via the API, and verify zero drift.
Before you begin
Your Terraform configuration is working and applied
You can run
terraform state pull(ortofu state pull) successfullyThe Bricks CLI is installed and authenticated (
bricks whoamireturns your user)You have an organization API token
Uploading a state file that does not match your configuration can cause drift or destructive changes on the next plan. Verify that your package version and state file correspond to the same Terraform code before uploading.
Step-by-step
Publish the package
Navigate to your Terraform codebase directory and publish:
bricks bp publishThis creates a versioned package in Bluebricks. Note the package version number from the output.
State uploads are version-scoped: the uploaded state must reference a specific package version. If you skip this step, the state upload will fail.
Create a blueprint
In the Bluebricks app, go to Packages
Click Create blueprint
Add your newly published package to the blueprint
Upload the state to Bluebricks
Upload the state file via the Bluebricks API:
curl -X POST "https://api.bluebricks.co/api/v1/envs/<ENVIRONMENT_SLUG>/states" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "packageVersion=<PACKAGE_VERSION>" \
-F 'states=[{"package_id": "<PACKAGE_ID>", "state_file": "terraform.tfstate"}]' \
-F "terraform.tfstate=@./terraform.tfstate;type=application/json"Replace:
<ENVIRONMENT_SLUG>
Your environment slug (visible in the Bluebricks app)
YOUR_API_TOKEN
Your organization API token
<PACKAGE_VERSION>
The version you published in step 1
<PACKAGE_ID>
The package ID used in the blueprint
The state file must be valid JSON.
Troubleshooting
Plan shows full recreate: check that the package version matches the original Terraform code, variables are identical, provider configuration has not changed, and the correct state file was uploaded. Re-upload the matching state file if needed.
API upload fails: verify that your API token is valid, the packageVersion exists, the package_id is correct, and the state file is valid JSON.
Environment slug not found: confirm the blueprint was installed successfully and the slug matches the one used during installation.
Related
Terraform/OpenTofu overview (Docs)
State Management and History (Docs)
API Authentication (Docs)
Last updated

