_images/login_button.png _images/signup_button.png



Sharing Workspace State

Reading time: 2 minutes

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 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 = "<org_id>"
    workspaces = {
      name = "<workspace name>"
    }
  }
}

When a terraform_remote_state block in in a Terraform configuration this provides access any outputs in that remote state.

terraform_remote_state data sources are fully supported in Scalr. A Terraform configuration can reference the outputs of any other workspace in any other Scalr environment that a user has access to.

Example

This example shows how to access the remote state for workspace ‘share-state’ in the ‘Dev’ environment in the Scalr SaaS system at my-account.scalr.io. For self hosted systems use the URL of the Scalr installation.

  1. Get the organization id from the environment switcher on the UI

    _images/org_id.png

    or from the environment dashboard.

    _images/org_id2.png
  2. Get the code snippet for the terraform_remote_state from the workspace dashboard. Note that this includes an example for referencing the output (commented out) and all the outputs are listed below.

    _images/rs-snippet.png
  3. Then add the snippet to the Terraform configuration and reference the outputs as required. In this example we are assigning the private IP to a local.

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

  config = {
    hostname = "my-account.scalr.io"
    organization = "org-ssccu6d5cxxxxxx"
    workspaces = {
      name = "share-state"
    }
  }
}

locals {
  scalr_test_private_ip = data.terraform_remote_state.share-state.outputs.scalr_test_private_ip
}