State Migration

For State Migration to work, please make sure the following conditions are met:

  • if you're migrating the state from another Remote Backend, make sure you are logged in to the previous Remote Backend
  • Terraform is configured to run with the current backend - this can be done by running terraform init (this is needed for Terraform to detect the changes in the Backend configuration)
  • You're logged in to the env0 Remote Backend
  • You have your Organization ID and your Project ID

Migrating the state is fairly simple. All you have to do is:

  1. Configure the Remote Backend in your Terraform code:
terraform {
  backend "remote" {
    hostname = "backend.api.env0.com"
    organization = "<YOUR_ORGANIZATION_ID>.<YOUR_PROJECT_ID>"

    workspaces {
      name = "<YOUR_WORKSPACE_NAME>"
    }
  }
}
  1. Run terraform init -migrate-state -force-copy

That's it!

The migration results with:

  • A new Environment in the given Project, its name is as the given Workspace Name
  • The Environment's current state will be exactly like the current state of your previous Backend

🚧

Insert Missing Definitions Into Your Generated Environment

Since Terraform sends limited data for creating the Environment, there are a few things the generated Environment and its matching Template are missing.

The Environment is missing Continuous Deployment configuration.

The Template is missing VCS configuration (repository, branch, terraform folder).

We recommend filling in those missing definitions so you can deploy your Environment remotely in env0 and fully leverage all of the env0 capabilities and features.


Did this page help you?