@here can anyone tell me if there is a supported w...
# general
b
@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
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):
Copy code
from pulumi import StackReference

ref123 = StackReference(f'abc/123/dev')
ref123_output = ref123.get_output("ref")
b
how do I find out our org?
e
Not sure if stack references work on S3 backend.
r
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
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
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
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
(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
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
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