https://pulumi.com logo
#getting-started
Title
# getting-started
a

acceptable-notebook-17653

12/03/2021, 7:40 PM
Hello everyone! At my company we are evaluating Pulumi to help us manage kubernetes infrastructure on multiple clouds. We are just starting out! One thing we are trying to get straight in our minds is the Project and Stack relationship and practices the community follow. From reading through the documentation, we want to create a project and then add stack’s to that project. I am curious and wondered if anyone would mind commenting on how they setup up and organise their
project
and
stack
. We are using pulumi version v3.19.0 Thanks
I can’t quite grasp how to start out a project. Should we use
pulumi new
command but only generate a project. Then to add a stack
pulumi stack init
?
g

green-stone-37839

12/03/2021, 7:44 PM
By default
pulumi new...
will create a project and ask you to create a single stack as well. If you'd like to add additional stacks to a project,
pulumi stack init...
is the command you'd use.
a

acceptable-notebook-17653

12/03/2021, 7:45 PM
Thanks! I was hoping we could somehow use
pulumi new
to add more stacks as we would benefit from pulumis’ built in ability to install dependencies etc
g

green-stone-37839

12/03/2021, 7:46 PM
A common use-case for setting up projects and stacks is to associate your Pulumi projects to an application and stacks to different environments. So say you had a 3 tier web-app called MyWebApp, the project would be
MyWebApp
and your stacks could be associated to your different environments, like dev, test, stage, prod, etc.
a

acceptable-notebook-17653

12/03/2021, 7:49 PM
Thanks, I am wondering how we would spin just the kubernetes infrastructure. In our minds we would have in a git repository a top level directory called clusters, which is also the project. Then we would have a number of sub directories which are the stacks e.g.
Copy code
clusters/
├── eks-eu-01
└── eks-eu-02
g

green-stone-37839

12/03/2021, 7:50 PM
Yeah, that's a useful pattern.
a

acceptable-notebook-17653

12/03/2021, 7:51 PM
So far I tried
Copy code
pulumi new go --generate-only --name clusters --description 'Kubernetes clusters'
and then I setup the stacks
pulumi stack init --stack eks-eu-01
g

green-stone-37839

12/03/2021, 7:52 PM
By default, stacks will be located in the same directory as the
Pulumi.yaml
file which tracks the project.
a

acceptable-notebook-17653

12/03/2021, 7:52 PM
but they are basically empty and I don’t get the benefit of the buitin ability of the cli to setup the environment for the stack
g

green-stone-37839

12/03/2021, 7:52 PM
By environment for the stack, do you mean configuration values?
a

acceptable-notebook-17653

12/03/2021, 7:54 PM
yeah - so if we use python for our project, the stacks don’t get setup with a virtual env for example
does that make sense?
So if I run the following commands…
Copy code
pulumi new go --generate-only --name clusters --description 'Kubernetes clusters at <http://example.com|example.com>' --dir clusters
cd clusters
pulumi stack init --name eks-eu-01
I end up with this layout…
Copy code
clusters
├── Pulumi.yaml
├── eks-eu-01      <-- stack
├── go.mod     <- this seems redundant   
└── main.go    <- this too
In the above example the root stack seems not useful for our use case and the stack doesn’t contain anything
Which results in the desired stacks from the pulumi service
Copy code
pulumi stack ls
NAME       LAST UPDATE  RESOURCE COUNT  URL
eks-eu-01  n/a          n/a             <https://app.pulumi.com/example/clusters/eks-eu-01>
I then want to add another stack so I run
Copy code
pulumi stack init --stack eks-eu-02
For those stacks I have to manually create the directory
mkdir eks-eu-02
It feels like I am not understanding the expected use of Projects and Stacks
I think I get this now. So in our use case a project contains a “program” that contains a resource, in our case an eks cluster. A stack is used to feed that program with specific and different configuration
b

billowy-army-68599

12/04/2021, 12:18 AM
@acceptable-notebook-17653 I'm happy to jump on a call with you to talk through this if it makes it easier to grok?
but I think you've come to the correct conclusion: • program - the Pulumi code that is run by the pulumi program • stack - a reusable instance of a Pulumi program with unique configuration. It exists within a project, and then can be many stacks • project - a grouping of a program, and one OR many stacks
you shouldn't have to create a new directory for each stack
👍 1
a

acceptable-notebook-17653

12/05/2021, 4:52 PM
Thanks so much for the offer @billowy-army-68599, and for confirming I am on the right course now 👍. The penny finally dropped!
4 Views