Terraform Backend Migration: A Journey Worth Taking

Mohammad Asim Ayub
CodeX
Published in
3 min readFeb 4, 2023

--

In this blog I want to share with you my journey and discovery of migrating my projects backend from terraform cloud.

Photo by Florian Krumm on Unsplash

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.

  1. Backend configuration in your project.
  2. 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…

--

--

Mohammad Asim Ayub
CodeX

A DevOps engineer by profession. I love learning about new technologies and sharing my learning with others. Visit me @ www.asimayub.com