Apply for invite to IaCP

Migrating to Scalr

Overview

A lot of Terraform users will already be using Terraform locally and/or storing state in a remote backend such as S3 or TFE/C. As your usage of Terraform scales up you will see the need to take advantage of the features Scalr as a remote backend for operations and state.

To take advantage of these benefits you will need to migrate the Terraform state from your local machine or from a other remote backends. Both can easily be done with Scalr using the Terraform CLI.

The exact steps you need to follow vary depending on whether you are migrating from local usage (Terraform OSS) or from another remote backend.

Preparation

You must start by configuring the CLI with an API token so it can connect to Scalr. Also ensure you have the right Terraform version and active pipelines are stopped.

  1. In the Scalr UI Create an API Token

    ../_images/api_token.png
  2. Add the API token to your CLI Configuration file.

    OS

    File name and location

    Windows

    file must be named named terraform.rc and placed in the relevant user’s %APPDATA% directory. The physical location of this directory depends on your Windows version and system configuration; use $env:APPDATA in PowerShell to find its location on your system.

    All other

    ~/.terraformrc

    credentials "my.scalr.com" {
      token = "<user-token>"
    }
    
  3. Ensure that you are using Terraform 0.12.0 or higher.

  4. Stop all runs and existing pipelines to ensure data integrity.

Migrating from TF OSS

You can migrate to Scalr using your current working directory, or you can clone the directory first to allow you to verify the process without impacting your existing locally stored state files. Follow this if the either of these scenarios applies use case:

  • Locally stored state

  • Standard remote backend state storage, like S3. (Go to the next section if you are using an enhanced remote backend)

In either case, ensure that the terraform.tfstate exists in your working directory, if not, copy it into your working directory.

Important

If you clone your working directory, you MUST copy the terraform.tfstate files.

  1. Add the remote backed terraform { } code to your template to point to Scalr. You can get the organization id from the dashboard or environment switcher on the UI. The workspace can be pre-created in the Scalr UI or you can let terraform init do it in the next step.

    ../_images/org_id.png
terraform {
backend "remote" {
  hostname = "your.scalr.com"
  organization = "<organization-id>"
  workspaces {
    name = "<workspace-name>"
    }
   }
  }
  1. Run terraform init and the workspace will be created with the latest state file. When you are asked if you want to copy the existing state, say “Yes”.


Migrating from an Enhanced Remote Backend

These steps will migrate the state stored in another enhanced remote backend into Scalr.

  1. Change the existing remote backed terraform { } code in your template to point to Scalr. You can get the organization id from the dashboard or environment switcher on the UI. The workspace can be pre-created in the Scalr UI or you can let terraform init do it in the next step.

    ../_images/org_id.png
terraform {
backend "remote" {
  hostname = "your.scalr.com"
  organization = "<organization-id>"
  workspaces {
    name = "<workspace-name>"
    }
   }
  }
  1. Run terraform init and the workspace will be created with the latest state file. When you are asked if you want to copy the existing state, say “Yes”. The Terraform CLI will automatically migrate the state from the old remote backend to Scalr.