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 valuerunner-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 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 is in a Terraform configuration this provides access to any outputs in that remote state.
The 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 it has access to. To access the other states, a Scalr access token must be assigned as a shell variable in the workspace. That token must have permission to access the workspace and state. See more on IAM and service accounts here.
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