StackReference: How does it work? I have pulumi p...
# general
b
StackReference: How does it work? I have pulumi project A with stack S-A and project A/B with stack S-B. There is a lot of confusing behavior with trying to stack reference using pulumi.StackReference('<org>/S-B') from project A. The example in pulumi/examples doesn't really cover this situation. The example has projects A,B,C and C references B and A. And how do organizations fall into the stack references?
p
I'm only just using them - but from what I can tell, it's straight
org/stack-name
(drop the org part for s3 based state).
what are your stacks named?
g
... = new pulumi.StackReference("org/project/stack")
is the expected patttern
so in my case this would be a proper stack reference usage:
... = new pulumi.StackReference("clstokes/aws-ts-webserver/dev")
b
Hmm - does the folder that project is contained in have to match the project name?
p
question as a s3 state user who hasn't used the saas backend: in
"clstokes/aws-ts-webserver/dev"
dev
is your stack name? and
aws-ts-webserver
is the filesystem folder your project is in (or otherwise named in pulumi.yaml)?
g
Copy code
org: clstokes
project: aws-ts-webserver   # from Pulumi.yaml 
stack: dev
b
Im trying to reproduce a reliable problem now using the pattern @gentle-diamond-70147 outlined. But so far havent
My folder is not named the same as the project name
g
@brave-salesmen-42327 it does not have to match the folder name, no
b
Yeah I think I just let a incorrect pattern in the new StackReference() creep in
i had a mis match with the project name
Im trying to break it now but so far so good
See if the diagrams help explain what @gentle-diamond-70147 is explaining
I was learning myself so tried to visualize project mapping to stacks as I worked with gitlab pipelines
b
Ok so I think it was just the mismatch of the stackreference org/project/stack . I had renamed the project portion of it and didn't update the stack reference call.
👍 1
Im not sure what state I pushed everything into, but I had to state delete some dangling things, and refresh some things, but it all seemed to come together after I fixed the original problem and rebuilt everything.
Thanks for the comments and help, All!
Additional data point: Not only did I have a misnamed stack reference, but My profile was set to another account. So I was building into our sand box account instead of the correct one. ugh. That really messes the stacks up looks like. I am going to have to include some profile checking at the beginning of these build scripts. I wonder if there is an appropriate place to record user information of who ran the stack in pulumi. Because it doesn't appear to handle switching accounts well. It's certainly my mistake, but some tooling help might saving some people some pain.
And if the user is in another AWS account entirely based on the profile used, that's a problem.
p
you can put
aws:profile:
in your stack config
I've found that helps a ton
in my s3 state world I ended up enforcing that with a wrapper, and always unset the env vars (which means some hoop jumping, but I have to do that anyway with mfa restrictions and cross account role assumption etc)
b
Yeah - ima have to do that.
I just stomping through all my stuff with big shoes and no eyes or brains right now.
feels bad man
p
it's even harder with s3 state because you have to
pulumi login new-account-bucket
for each account switch
b
yeah that feels painful
p
haha, yeah - know what you mean
b
Should have taken a nap instead
p
so
pulumi
is now a 140 line shell script wrapper....
(that doesnt include the aws auth logic, that's an external tool)