https://pulumi.com logo
#typescript
Title
# typescript
s

salmon-fish-42319

12/09/2021, 7:36 PM
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

wonderful-twilight-70958

12/09/2021, 8:08 PM
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

little-cartoon-10569

12/09/2021, 8:18 PM
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

salmon-fish-42319

12/09/2021, 8:55 PM
oooh nice, thanks for both of the replies. Gives me some things to consider
h

happy-parrot-60128

12/09/2021, 9:22 PM
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

salmon-fish-42319

12/09/2021, 9:28 PM
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

miniature-king-36473

12/10/2021, 2:11 PM
+1 for using ComponentResources.