https://pulumi.com logo
Title
b

brash-quill-35776

08/10/2021, 3:14 PM
Hi, I found that I can't create stack with same name under different projects Details is illustrated in https://github.com/pulumi/pulumi/issues/7728 I assume we should be able to create stack with same name in different projects right? Like to create
dev
in both project A and B
p

prehistoric-activity-61023

08/10/2021, 3:16 PM
You should. Actually, I’ve got 2 projects with linked stack names.
The only diff I was able to spot right now (without further analysis) is that you’re using GCS as state storage instead of Pulumi Service.
b

brash-quill-35776

08/10/2021, 3:17 PM
that's what I thought but when I try to do so, I always get
stack dev already exists
oh? I have tried both
local
and
gcs
, none of them supports that feature. With that said, seems like only pulumi service supports this feature then?
p

prehistoric-activity-61023

08/10/2021, 3:19 PM
I’m not suggesting that it’s not possible while using GCS - I haven’t checked that.
I’ll try to take a look at that but I don’t have much free time right now. Could you double check if that case is reproducible for you while using Pulumi Service? You should be able to test that using free individual account.
b

brash-quill-35776

08/10/2021, 3:21 PM
will try that for sure
p

prehistoric-activity-61023

08/10/2021, 3:23 PM
Ok, I’ve tried to repro this (using Pulumi Service) and everything works just fine.
I was able to create two projects using:
pulumi new google-native-typescript --dir <DIR_NAME>
with the same stack.
b

brash-quill-35776

08/10/2021, 3:24 PM
I just tested with pulumi service as well it works!!!
I think the official doc should make this point clear that only pulumi service support that feature
thanks for pointing this out, I thought I made some weird mistake myself, now it's clear
p

prehistoric-activity-61023

08/10/2021, 3:27 PM
Ok, I think I have the anwser for you
I don’t have time to play with the GCS backend but I’ve looked into the local backend
b

brash-quill-35776

08/10/2021, 3:28 PM
ya found that in
local
, all stack files are placed in same folder
p

prehistoric-activity-61023

08/10/2021, 3:28 PM
When you configure local backend e.g. with:
export PULUMI_BACKEND_URL=file:///tmp/tests/state
Stacks are stored directly under that directory and they do not include project name.
b

brash-quill-35776

08/10/2021, 3:28 PM
with only stack name as file name, for instance
dev.json
etc.,
p

prehistoric-activity-61023

08/10/2021, 3:28 PM
exactly
so if you want to use something other than Pulumi Service, you’re responsible for configuring the state backend properly
e.g. by providing different directories for each project in case of local backend
and I guess by providing different buckets (or path prefix) in case of GCS/S3
b

brash-quill-35776

08/10/2021, 3:30 PM
I see! that's a brilliant catch thanks
🙌
p

prehistoric-activity-61023

08/10/2021, 3:34 PM
I cannot advice you more as I have no experience with using pulumi with other state backends but I think you’ll manage to move further with this now 🙂. If I were you, I’d confirm that the case with GCS is similar to the local backend and if that’s so, check whether you can add a prefix to bucket URL (e.g.
<gs://my-bucket-name/my-proj>
instead of simple
<gs://my-bucket-name>
). You can dynamically change state backend via env variable:
PULUMI_BACKEND_URL
. Not sure if you can store it in pulumi yaml file.
b

brash-quill-35776

08/10/2021, 3:35 PM
ya that's what I am planning to test now, hopefully by doing so I can mimic what pulumi service's behavior
thank you so much sir!
p

prehistoric-activity-61023

08/10/2021, 3:35 PM
EDIT: you should be able to configure backend using YAML file, see https://www.pulumi.com/docs/reference/pulumi-yaml/. There’s an optional
backend
field.
b

brash-quill-35776

08/10/2021, 3:37 PM
nice, this can be much easier and switching env var back and forth
p

prehistoric-activity-61023

08/10/2021, 3:37 PM
exactly
b

brash-quill-35776

08/10/2021, 3:37 PM
🎉
let me test it out
p

prehistoric-activity-61023

08/10/2021, 3:38 PM
There’s just one thing that’s missing when you decide to use other state backend (other than the lack of UI) - there’s no locking mechanism that could prevent simultaneous runs of
pulumi up
.
Although I’m not 100% sure I’m right in that matter.
b

brash-quill-35776

08/10/2021, 3:40 PM
ya, looks like pulumi service cover all those cases, whereas the others we have to do these all by ourselves
p

prehistoric-activity-61023

08/10/2021, 3:48 PM
Ensuring that you have different paths for different projects shouldn’t be a problem.
b

brash-quill-35776

08/10/2021, 3:48 PM
definitely!
p

prehistoric-activity-61023

08/10/2021, 3:48 PM
Ensuring you won’t have two simultaneous updates running on the same stack might be trickier.
If you have one devops guy -> no issues. If you use ONLY CI/CD and you can put restrictions on number of parallel runs -> cool. If you want to make it bulletproof, you need to wrap
pulumi up
with some additional logic and implement simple locking mechanism (e.g. similar to what TF done in case of S3+DynamoDB).
b

bored-oyster-3147

08/10/2021, 3:49 PM
With self-storage stack names are globally unique instead of project unique. The solution is to either namespace your stacks with the project name or to specify separate backends. Note that if you use separate backends than you won’t be able to make StackRecerences to different backends
There was a recent merge into Pulumi that added update concurrency locking on the file state backends
p

prehistoric-activity-61023

08/10/2021, 3:51 PM
Arr, thanks @bored-oyster-3147 for pointing that out. Not being able to use stack references might be a real issue. @brash-quill-35776 make sure you won’t need that (I’m afraid you’ll need it sooner or later though)
b

brash-quill-35776

08/10/2021, 3:51 PM
@bored-oyster-3147 ya I was planning to prefix the stack name with project, which is not nice looking but not too bad anyway
p

prehistoric-activity-61023

08/10/2021, 3:52 PM
that actually seems like the easiest solution without any downsides except “not so pretty stack names”
b

brash-quill-35776

08/10/2021, 3:52 PM
ahhh
StackReference
is a requirement for my project. then in this case, I have to prefix then
ya, agree
p

prehistoric-activity-61023

08/10/2021, 3:52 PM
There was a recent merge into Pulumi that added update concurrency locking on the file state backends
I didn’t know that. Are there any docs created describing that?
b

bored-oyster-3147

08/10/2021, 3:59 PM
I believe this is what I was thinking of. So it was implemented previously and can currently be enabled via an environment variable and they haven’t yet made it default
🙌 2