Hello. I've been going through <https://www.pulumi...
# getting-started
s
Hello. I've been going through https://www.pulumi.com/blog/iac-recommended-practices-code-organization-and-stacks/ to figure out how to organise projects/stacks/resources. How do you structure stuff for how the resources (AWS) to be created could differ between environments for the same app . eg "dev" just needs an S3 bucket; "staging" needs an S3 bucket (different name) but also an RDS instance which "dev" doesn't need; "prod" has S3 + RDS + XYZ? Thanks
l
If it really is within the stack, and the deployment schedule isn't different, then use
if (stackName == "prod") { .... }
However, for long-lived environments, you'll often find that there's more than one deployment schedule. For example, the RDS instance would be deployed very very infrequently, whereas app deployments might happen quite frequently. This would suggest that you need multiple projects.
s
Thanks for the comments. I was going the conditional way but wasn't sure if that was a good way. I feel like the multiple project approach would result in code duplication, unless I'm not getting what a "project" is🤔
l
You shouldn't duplicate code between projects.
A project is best used as a group of resources that need to be deployed / updated / destroyed together. A stack is a target environment. So a common pattern is to have a grid of projects and stacks. You might have network, database and app projects; each might have dev, test, prod-eu and prod-us stacks.
So when you deploy your dev stack, you'd run
pulumi up
in your network project, then your database project, then your app project. And when you update your dev app, you run
pulumi up
in your app project, but don't touch your network or database projects.
s
Ah ok, makes sense. Thank you!