Terraform Backend Migration: A Journey Worth Taking
In this blog I want to share with you my journey and discovery of migrating my projects backend from terraform cloud.
Terraform cloud is an awesome tool. It provides a number great features and I would highly recommend it. However, there are times when you have to migrate from it. Officially migration from terraform cloud backend is not supported, however, I recently tried to do it and I wanted to share it with you here.
Terraform provides support for a number of backend. A backend is an API and a storage endpoint. Terraform uses this information to write its state file into the backend. It keeps references to a project’s backend in two places.
- Backend configuration in your project.
- In
terraform.tfstate
file in.terraform
folder.
Usually when migrating from one backend to another, you update your backend configuration in your project and then run the command, terraform init --migrate-state
. However, this will not work when migrating from the cloud to another backend.
To achieve this we have to first get a copy of the state file in the cloud. Terraform cloud provides us an option to download it. As a precaution, I would first ensure that there are no drifts between the code and infrastructure. I would also implement these changes…