Thread
#typescript
    s

    steep-toddler-94095

    3 weeks ago
    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

    3 weeks ago
    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.
    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.
    r

    ripe-russia-4239

    3 weeks ago
    @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

    3 weeks ago
    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
    r

    ripe-russia-4239

    3 weeks ago
    Thank you so much!