Any tips for working with several stacks in a Pulu...
# general
w
Any tips for working with several stacks in a Pulumi monorepo? I'd like several projects each in its own folder, with their own
Pulumi.<env>.yaml
files. But, if I do something like,
pulumi stack init dev
, say without one of these
Pulumi.xxx.yaml
files in place, it would generate a file called
Pulumi.dev.yaml
, and a stack called
dev
. Then, if I attempt this in another project folder, it can't create the stack because there is already a stack named
dev
. There is no
--config-file
parameter on the
stack init
command, so I can't do something like,
pulumi stack init <project>-<env> --config-file Pulumi.dev.yaml
b
have you seen this? https://www.pulumi.com/docs/guides/organizing-projects-stacks/ anything in there helpful to you?
w
Yeah, I've been through those and that makes sense to me. But then when I start running actual
pulumi
commands to work with those repo layouts, things sorta break down for me. If I go in to one folder and do
pulumi stack init dev
it uses the
Pulumi.dev.yaml
file, and creates a stack called
dev
. If I go in to another folder, also with a
Pulumi.dev.yaml
file, how can I do another
pulumi stack init dev
as there is already a stack called
dev
?
b
to make sure i understand what you are trying to do. this is what i think ur saying.. 1. create a new folder 2. create new project A, and a new stack named dev within that project 3. now you want to create a new project B that lives inside the project A folder and that project B will have a stack named dev is that correct?
w
Copy code
|-projects
 |-project-A
  |- Pulumi.yaml
  |- Pulumi.dev.yaml
 |-project-B
  |- Pulumi.yaml
  |- Pulumi.dev.yaml
If I run
pulumi stack init dev
in
projects/project-A
, I get a stack called
dev
. If I go to
projects/project-B
and run
pulumi stack init dev
, I get
error: stack 'dev' already exists
two folders, two stacks, one
dev
if I run
pulumi stack init project-A-dev
it creates a new
Pulumi.project-A-dev.yaml
file
b
oh i see i think this is a fully qualified name issue; quick question are you using the pulumi cloud (previously named pulumi service), or your own backend?
also what version of the cli?
w
No, I'm just storing state locally, also experimenting with an S3 backend. Version is
v3.65.1
It's a bit of a meta-project to perfect a local only IaC workflow specifically
b
okay im not as familiar with the setups for folks using their own backend, so imma leave this question for someone else to answer. but if no one else does ill dive back into this tomorrow.
w
Cool thanks! For anyone else who can help, disregard the S3 backend, I'm really focused on making this work with
pulumi login --local
for integration testing in CI with localstack.
f
Maybe specifying the backend in Pulumi.yaml will work for you @wooden-queen-36575? As in https://www.pulumi.com/docs/intro/concepts/state/#logging-into-and-out-of-state-backends
Copy code
....
backend:
  url: <backend-url>
....
I never do
pulumi login
as it differs between people. I just have it set in the config so it's the same for everyone.
(never had this use case, though)
w
File state backend recently added project support. I can’t find the release notes right now. It’s 1AM in my time zone. But I would expect that to help.
w
Oh, nice, yeah that sounds like what I'm looking for, will look in to it!
I found the blog post discussing this feature, and it doesn't seem to work as expected. If I run
pulumi stack init dev
in a different project folder, it returns
error: stack 'dev' already exists
. I have tried completely clearing out my local state, including my
~/.pulumi
folder, hoping that the local file backend will be upgraded to use the new mechanism.
w
Did you migrate your filestate backend to the new project format first?
w
That turned out to be the problem... the migration was a little confusing at first, and I didn't manage to successfully perform the migration.