so far i've just been using functions for everythi...
# typescript
s
so far i've just been using functions for everything but recently am looking into component resources. is there a recommended way to handle breaking up the code in a component resource so i don't have a (for example) 3000 line constructor?
l
Treat it as you would any other OO class. You want cohesion, SOLID, all the usual good stuff.
If you want to set up your database with AWS backup, and a native backup to a common backup S3 bucket, then set up RDS and AWS Backup in the constructor. Don't set up the S3 bucket, pass that in as a parameter. It's all fairly intuitive.
👍 1
Also design everything to be unit testable. Component Resources' winning feature (for me) is that it lends itself to TDD in a way that almost nothing else in IaC does.
p 1
r
@little-cartoon-10569 do you have any examples you can share? My experience of writing tests for Pulumi code has been frustrating at best, so I'd love to see some that are working well for people.
l
I've lifted this from closed-source code and anonymized it. Hopefully there's nothing private left in there 🙂 And I haven't run it separately, but hopefully you can make it work? It depends on mocha, chai and chai-as-promised. https://gist.github.com/tenwit/bc47bc664c2862db172743429c0ce453
💜 1
r
Thank you so much!