Sharing Workspace State
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 ‘CS-M’ environment in the Scalr SaaS system at my-account.scalr.io.
- Get the organization id from the environment dashboard:

- Get the code snippet for the terraform_remote_state from the workspace dashboard by clicking on output usage. Note that this includes an example for referencing the output (commented out) and all the outputs are listed below.

- 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
}
Updated 3 months ago