Sharing Workspace State

❗️

Sharing State Between Environments

State sharing between environments is disabled by default. To share the state between environments please set a shell variable SCALR_RUNNER_ROLE with the value runner-account-access at the account scope.

It is common practice to reference outputs from other workspaces so that a Terraform configuration can make use of resources that have been deployed in another workspace. This is known as “remote state” and accessing the remote state is done using the terraform_remote_state data source as shown in this example.

data "terraform_remote_state" "state-1" {
  backend = "remote"

  config = {
    hostname = "<host>"
    organization = "<env_id>"
    workspaces = {
      name = "<workspace name>"
    }
  }
}

In Scalr, a workspace can reference the outputs of any other workspace in any environment if SCALR_RUNNER_ROLE=runner-account-access has been set as a shell variable at the account scope. Alternatively, if SCALR_RUNNER_ROLE is not set at the account scope, then workspaces will only have access to the remote state files within the same environment.

Remote State Code Snippet

To obtain the remote state code snippet for a workspace, go to the workspace dashboard and click on Output Usage. A code snippet similar to the one above will be provided which can then be pasted into your Terraform code.