1

My objective is to organize my iac resources in familiar tiers (pulumi micro-stacks) like network, db, app, etc. As an example, I have two pulumi projects created in sibling folders using file:// backend (pulumi login file://.)

someroot/iac1
someroot/iac2

I want iac2 to StackReference iac1's exported values.

In iac2 code, I have tried different combinations to reference iac1.

let iac1 = new pulumi.StackReference("iac1");
let iac1 = new pulumi.StackReference("iac1/dev");
let iac1 = new pulumi.StackReference("../iac1/dev");
let iac1 = new pulumi.StackReference("iac1-dev");

Error:

  pulumi:pulumi:StackReference (../iac1/dev):
    error: unknown stack "../iac1/dev"

I think i am missing something simple. I have also tried nesting the folders.

Thanks.

S2L
  • 1,746
  • 1
  • 16
  • 20

1 Answers1

1

StackReference needs to point at a stack not a project. So, if you do something like:

pulumi stack init network-dev
pulumi up

pulumi stack init db-dev
pulumi up

Then in another project you can create stack references like:

let networkStack = new pulumi.StackReference("network-dev")
let dbStack = new pulumi.StackReference("db-dev")

Best practice would actually be to get the current stack programmatically (see https://www.pulumi.com/docs/intro/concepts/stack/#getting-the-current-stack-programmatically) and use that to construct the name of the other stacks. The idea being that you may have a "network-dev", "network-staging", "db-dev", "db-staging", etc.

Mitch G
  • 196
  • 1