Hi all. When it comes to separating resources by t...
# getting-started
c
Hi all. When it comes to separating resources by their lifecycle, should I be using different projects or different stacks? Based on the online docs it looks like separate projects would be the correct approach, but that just seems counterintuitive. As an example, if I had a project on AWS which involved an s3 bucket and network which should be kept alive, then an EC2 instance I'd like to be able to spin up/down as needed, how would I best organize that?
f
It depends 🙂 in your specific case, my initial thought would be to have those as two different projects as it sounds like they aren't related anyhow. You could keep all 3 resources in a single project and make the EC2 resource conditional upon e.g. a config key or similar. What's feeling counterintuitive to you?
c
Okay, that's what I was tracking based on the docs as well. I think it's the terms "projects" and "stacks". I was using the AWS CDK before trying Pulumi, and had those resources in separate stacks (a stateful and a compute stack), so I probably just need some time to get used to the new definition.
As far as projects go, I typically think of the project as the top level unit of organization, which it wouldn't be in this case.
f
Yeah, for sure. Take your time fully understanding the concept of Pulumi stacks as they're really the foundation for... well, just about everything in Pulumi 😄
image.png
each program has 1 or more stacks - in that img they're named dev/qa/prod
stacks have their own set of config
"You end up having Programs instantiated by Stacks driven by Config."
so back to your use case, I would start with the (somewhat ephemeral?) EC2 instance being in its own program just for clear separation of concerns. That decision could be overridden by other factors as I become aware of them
c
That is fair, the idea of stacks does make sense, and had I not come from CDK prior to this I'd probably not have the same holdups.
If I then had a coworker who wanted to spin up their own program (assuming it's completely separated), they would want to create a separate stack for each project, correct?
Is there anyway to "group" the projects together to show they're related?
f
you can 'tag' stacks and then group them in Pulumi Cloud; that's really handy
(not sure if you're a user of Pulumi Cloud or not)
c
I haven't looked at Pulumi Cloud just yet, but it is in my todo list
👍 1
f
you can def still use tags, you'd not have the fancy view of them in a UI is all
re: coworker - is that "their own program" literally their own? or are you two sharing it in some capacity? note that each Program needs at least one Stack
because if you're sharing the program, remember that a Stack is an instantiation of it - unless we're talking about e.g. a "dev stack" where each of you have your own instances in the cloud - you'd want to share the Stacks as well
c
That's a fair point, and in this case I don't have an answer, probably because it really doesn't make sense in the hypothetical 🙃 . I'll keep working and see what makes sense.
👍 1
One last question while I have your attention, if a resource is available in both the Classic and Native providers, is the native the "better" one to use?
f
That's another "it depends" from me 😄 In my current experience, for AWS, Classic is fine. AWS Native is in preview but has resources available that Classic does not. It's perfectly fine to have and use both in the same program.
c
Makes sense, but if a resource is in both is there an advantage to using one over the other? Like the word "Classic" makes me think that one may eventually be deprecated, so would I be better off using Native where I can for better future proofing?
Not trying to split hairs just to be difficult, I promise 🙂
f
No worries! 😆 "Classic" does sound a lil scary, but I'd say don't worry re: future proofing. The one major difference - IMO - is that the documentation is currently "better" for Classic. As someone just starting out, you will probably benefit most from that. Classic: https://www.pulumi.com/registry/packages/aws/api-docs/ec2/instance/ Native: https://www.pulumi.com/registry/packages/aws-native/api-docs/ec2/instance/ You might also like https://www.pulumi.com/docs/clouds/aws/guides/ and the
awsx
package https://www.pulumi.com/registry/packages/awsx/ as it gives you some best-practice building blocks so you can move quick
c
Much appreciated, thank you. I would suggest (in my humble opinion) adding something to the docs of the providers to that effect, as the note in each just says to use the other if a resource isn't available, but nothing about what to use where they are both available.
And thanks for the links, I was using Crosswalk where it had the resources I needed 🙂
high five 1