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

steep-toddler-94095

08/31/2022, 4:35 AM
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

little-cartoon-10569

08/31/2022, 4:38 AM
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

ripe-russia-4239

09/01/2022, 11:27 AM
@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

little-cartoon-10569

09/03/2022, 12:20 AM
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

ripe-russia-4239

09/04/2022, 10:58 AM
Thank you so much!
2 Views