copying here from <#CJ909TL6P|typescript> : Can y...
# getting-started
f
copying here from #typescript : Can you please share some good reference example of organizing pulumi TS project in multiple files, folders, etc. Smth small just for starters, like maybe lambda deployment via S3 on custom domain and static frontend... I just want to see best practices on file organization
s
Are you asking for recommendations on organizing the Pulumi code itself, or the Pulumi code in relationship to other code in the same repo?
f
pulumi code itself is priority, but business logic placement won't hurt too šŸ™‚
s
When it comes to organizing the Pulumi code itself, generally our recommendation is "Follow the guidelines/recommendations for whatever language you're using." So, feel free to split up your code and organize in files/folders in whatever way TypeScript allows or recommends. The one "gotcha" I've found (and it's not really even a gotcha) is that it's very common to reference Outputs of one resource as Inputs to another resource, so pay attention to variable scope as you organize your code.
f
yep, I saw the docs, but I do not have much experience with TS I saw pretty comprehensive examples for AWS CDK but I'm looking for better ones and may be specifically for Pulumi
s
If you want to share the link(s) for AWS CDK, I can tell you if some of their recommendations would also apply to using TypeScript with Pulumi. I'll also see if perhaps I can find some recommendations for you, but---in general---we follow the recommendations for the language itself.
f
As I was writing my osp+k8s automation with Go at first and then in Python I felt that indeed pulumi docs are missing a blog post or learn-pulumi section that goes into the project structuring. Most examples shovel everything in a single file. While this is the most simple way of organizing things, I feel that some guidance on project structure is a good thing to have. For instance, for my Py project I felt that splitting various cloud domains in separate modules makes sence ā€¢ networking infra is its own module ā€¢ compute in its own ā€¢ outputs massaging in its own
Another interesting technique is reading stack configs in its own module Most examples go with
Copy code
cfg = pulumi.Config()
my_input = cfg.require_int("foo")
but for an input that is shared across the modules this would result in a code duplication. Instead one can create
config.py
(in their chosen lang) that reads all inputs and then consumers of it can import the resulting variable. All there is to say that these tricks are much welcome to be sourced by the pulumi authors offering (opinionated) approach to scalable and structured pulumi programs
f
Only applies for javascript/typescript projects I picked up Pulumi last month. I struggled with code organisation as well in the beginning. I usually build apps in typescript monorepos. After a bit of trial and error, I now always colocate pulumi code specific to an app in a subdir. This is how I organise my Pulumi code now. ā€¢ Shared infra like certificates, etc are independent workspaces in the monorepo ā€¢ Infra specific to an app is always colocated within the app workspace This AI example works pretty well for colocating infra and app code in a single project. https://www.pulumi.com/ai/conversations/c1535e56-a8d7-432d-a49f-fdd068cd98d1
f
@few-rainbow-35517 what about splitting large pulumi program into multiple files?
f
My code is not public. But I guess I can share a screenshot of how it looks like now.
f
that what I was looking for šŸ™‚
f
The whole idea of pulumi input and pulumi output is slightly mind bending when you first look at it. Took me a few hours to wrap my head around it. Once you understand how they work, code organisation will be easy.
I had all my code in a single file until I understood how to use
pulumi.Input
and
pulumi.Output
f
I have a very good project file separation for
yaml
(via spruce) but I do not think I will go with Yaml for more complex infras
I do wonder why nobody from Pulumi recommended the link šŸ˜ž