Does anybody have any pointers on typescript code ...
# typescript
s
Does anybody have any pointers on typescript code organization with Pulumi? I'm new to Pulumi in general, and working on building out a few environments containing infra and services. Most of the examples of Pulumi code just use a single index.ts file for defining everything, but I'd like to break it apart into multiple files at least, to try to keep things organized. Do people use components for making code more modular, or are there lighter-weight patterns that people rely on to be able to split up code?
w
I keep different 'layers' in different projects (and use stack references where necessary). Then I keep different functional / logical areas in different files in each project.
l
ComponentResources are very lightweight. I use them for everything. In addition to being Pulumi's answer to OO, they're also handy for expressing relationships and hierarchy in the
pulumi preview
graph.
s
oooh nice, thanks for both of the replies. Gives me some things to consider
h
I've sometimes just used plain old functions like
configureNetwork
- it's nice when trying to tidy up later on when resources are all created at the top level - at least functions let you break it down into smaller pieces and put them in different files. That said, ComponentResources are great when there's a clear boundary and grouping from the start
s
yeah I was trying with basic functions and getting hung up a bit on all the junk I end up needing to pass in and return back from the function
seems like functions make sense when you have a small function signature. things like "take some parameters and give me back a vpc object" definitely make sense as helper functions
m
+1 for using ComponentResources.