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

ambitious-flag-22427

09/27/2023, 6:00 PM
Is there a best practice around whether we should be exporting resources outside of index.ts? Almost every example only includes stuff in index.ts it seems, but my configuration is getting unwieldy.
f

full-eve-52536

09/27/2023, 6:05 PM
I'm not sure if there is a written Pulumi guide for that, but we organize all of our resources into separate files, as necessary. Our
index.ts
files are kept VERY simple. They only import said files in the desired order. For example:
With that said, of course that means that we
export
resources all over the place 😆
s

straight-cartoon-24485

09/27/2023, 6:20 PM
What do you export usually? ComponentResources, CustomResources, and/or (Dynamic) Providers?
f

full-eve-52536

09/27/2023, 6:22 PM
It typically depends on if we need that resource in another file. If we do, we
export
it. Providers for sure. We define that provider in it's own file and
export
it, then reference it in all of the files that require a Provider.
We do the same thing for ComponentResources, but don't really use CustomResources
a

ancient-car-89914

09/28/2023, 6:47 AM
in some situations where we have many sets of resources following the same pattern (conforming to the same interface(s)), we’ve resorted to this type of construction in index.ts:
Copy code
Promise.all(
  fs
    .readdirSync(__dirname + '/resources')
    .map(file => import(__dirname + '/resources/' + file))
).then(resource => {
// declaring further dependent resources here
}