ancient-megabyte-79588
08/20/2020, 5:20 PMexports
...
I have a pulumi app that is modularized in a simple Typescript fashion. I have a "MyModules" folder and I have files in there with exported functions. This all works great from running pulumi and letting me have manageable files to deal with. What doesn't work though is if one of these functions needs to export something out to the pulumi service as a stack output.
export const keyvaultId = keyvault.id
does not work in the function in the module. export
has to be outside of the function.
exports["keyvaultId"] = keyvault.id
and exports.keyvaultId = keyvault.id
which work in the function do not seem to be getting exported into the stack outputs.
If I put an exports.<name> = value;
in the top-level index.ts, it does work.
I would have expected the exports to work anywhere I use it and the stack output is correctly updated. Is this an incorrect expectation?little-cartoon-10569
08/20/2020, 9:02 PMsalmon-ghost-86211
08/21/2020, 1:00 AMlittle-cartoon-10569
08/21/2020, 1:16 AMancient-megabyte-79588
08/21/2020, 4:44 AMexports
object and they get exported when you are in the main pulumi index.ts. I couldn't get that approach to work in the modules, which are basically only an exported function.
So now, my module functions all return a {}:any
and they are all collected and then added to the exports
object in the top-level index.ts.
var toOutputs : any = {};
var newOutputs = module.Function();
toOutputs = {...toOutputs, ...newOutputs}
<repeat as needed>
Object.keys(toOutputs).forEach( key => { exports[key] = toOutputs[key]});
little-cartoon-10569
08/21/2020, 4:59 AMancient-megabyte-79588
08/21/2020, 6:20 AMexports
object into my module functions. 😄