Skip to content

Migrating Terraform state

Problem to solve

As a developer maintaining a Terraform/Terragrunt project which stores the tf state inside of GitLab (with the name being computed from the folder structure of the project, especially important for Terragrunt projects), I want to be able to migrate the state, so I can refactor project.

Proposal

I propose a CLI command to transfer the JSON file from one state to another:

glab state migrate OLD_NAME NEW_NAME

Further details

This will tremendously speed up refactorings of Terragrunt project following the following approach of structuring the project [1].

There is for example already an API endpoint for deleting a TF state stored inside of GitLab via it's name [3].

Links / references

[1] https://github.com/gruntwork-io/terragrunt-infrastructure-live-example [2] https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html [3] https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#remove-a-state-file-by-using-the-api

Edited by Alexander Padberg
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information