Terraform reference a workspace variable from another workspace

Viewed 17

I am wondering if achieving something like this is possible on terraform.

My environments.tf file where workspace variables are defined for each environment:

locals {
  env = {

    test = {
      ingress = {
      [...]
      cidr_blocks = "${local.workspace.pro.vpc.cidr}"
      }
    }

    pro = {
      vpc = {
        cidr               = "10.0.0.0/16"
        [...]
    }
  }
}

I would like to reference a hardcoded variable from the pro workspace. It is not viable the need to change the things on two sides when the values are the same.

What I have tried:

  • Referencing the variable from another workspace using:
local.workspaces["pro"]["vpc"]["cidr"]
local.workspace.pro.vpc.cidr

What I expect:

  • Grabbing the vpc cidr from the pro workspace and pass it to the test workspace.
0 Answers
Related