Migrating Terraform State to Terraform Cloud
In the previous recipe, we learned how to use Terraform Cloud as a remote backend. In Chapter 5, Managing Terraform State, we learned how to operate the state. We will now combine both of these skills into one project. In this recipe, we will learn how to migrate the existing state to Terraform Cloud.
In general, when you migrate a state from one backend to another, if you don’t follow the state migration procedure, Terraform will see a new backend in its configuration. Then, it will want to delete the resources, so you’ll have to recreate them in the new state, which will cause a service interruption.
To avoid having to reprovision resources, we need to migrate the state to Terraform Cloud.
Let’s get started!
Getting ready
To complete this recipe, you’ll need to use the same version of Terraform CLI between the time of the original state creation and the time you will operate the migration...