Is there a best practice around whether we should ...
# typescript
a
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
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
What do you export usually? ComponentResources, CustomResources, and/or (Dynamic) Providers?
f
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
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
}