https://pulumi.com logo
Title
b

bulky-policeman-29913

12/06/2021, 5:46 PM
@here can anyone tell me if there is a supported way to do a stack reference across different pulumi projects? Specifically we are using the AWS S3 backend and each project is in a new directory. Pulumi login though only logs into the active project, I would need to get shared resources from a different one.
g

great-queen-39697

12/06/2021, 5:51 PM
When you create a stack reference, you're calling it as
<org>/<project>/<stack>
. So if you're in an org called "abc" and the projects are "123" and "456" with stacks called "dev", you can call the stack details from "123" in "456" like this (this is in Python):
from pulumi import StackReference

ref123 = StackReference(f'abc/123/dev')
ref123_output = ref123.get_output("ref")
b

bulky-policeman-29913

12/06/2021, 5:55 PM
how do I find out our org?
e

elegant-window-55250

12/06/2021, 5:57 PM
Not sure if stack references work on S3 backend.
r

red-match-15116

12/06/2021, 5:57 PM
You're using the s3 backend so you actually don't have
org
...
stack references do work on s3 backend but all stacks need to be in the same bucket... not sure about the directory though. There are definitely some intricacies to making stack references work with s3 backend
b

bulky-policeman-29913

12/06/2021, 6:04 PM
thats the concern so say I have s3://bucket/project1
I do a pulumi login s3://bucket/project1
i dont think I can access with a stack reference project2 without a complimentary pulumi login right?
r

red-match-15116

12/06/2021, 6:05 PM
yah if you're logging into them separately with
pulumi login
I don't think
StackReference
will work. There are more details around this issue here: https://github.com/pulumi/pulumi/issues/2814
b

bulky-policeman-29913

12/06/2021, 6:06 PM
no im not
i mean I am for that project but not when project1 needs the reference
so in cicd it would only do pulumi login s3://bucket/project1
stack reference is going to have zero visibility to a different directory it knows nothing about right?
TLDR I think everything has to be at the root of .pulumi not nested for stack ref to work...but sadly that has issues cause of naming collisions among stacks (IE: cant have two stacks named dev)
r

red-match-15116

12/06/2021, 6:31 PM
(IE: cant have two stacks named dev)
For S3 backend it is recommended to include the project name in the stack name to avoid this issue and to keep all stacks in the same bucket (this will allow StackReference) i.e.
myproject-dev
and
other-project-dev
in one s3 bucket will allow StackReference
b

bulky-policeman-29913

12/06/2021, 6:37 PM
ok I was afraid of that...it would be nice if you could specify for the s3 provider like a relative path
../
or similar so you could get at other projects. Of course this isn't a problem with the pulumi console solution.
l

loud-rose-6296

03/25/2022, 3:51 PM
Let's say we have s3://bucket/.pulumi/stacks/Pulumi.Project1-dev.yaml and s3://bucket/.pulumi/stacks/Pulumi.Project2-dev.yaml . How could Project2 stackreference Project1 and what would its syntax be? cause the <org>/<project>/<stack> hierarchy does not exist here