In Terraform Cloud, we share state data between workspaces (if needed) in 3 possible ways.
Data Source (CURRENT implementation)
data "terraform_remote_state" "workspace" {}
- This method as of this writing, this method is the most simple way and what we currently use.
data "terraform_remote_state" "dispatcher" { backend = "remote" config = { organization = "safi" token = var.tfe_workspace_token workspaces = { name = "dispatcher" } } }
config {}
block support any available parameters that can be found here https://developer.hashicorp.com/terraform/language/settings/backends/remote#configuration-variables
token
- The token used to authenticate with the remote backend. We use “Team token” (under owners group) for this implementation https://app.terraform.io/app/safi/settings/teams/team-pSc2K67V2sXtJti1
Workspace ID (OLD implementation)
in tfe_workspace
resource block, passing list of workspace id in remote_state_consumer_id
parameters authorize other workspace to get data from the tf-state, previously we use this method but it needs additional or several conditions which complicates further the TF code.
Manual
you can authorize other workspace via UI Settings -> General -> Share with specific workspaces
Attachments:
Screen Shot 2023-01-05 at 1.43.37 PM.png (image/png)