Typescript noob question (feel free to tell me to ...
# typescript
c
Typescript noob question (feel free to tell me to RTFM): What is the canonical way to conditionally create a resource in pulumi? I have a module that does
export const nginxControllerChart = new ingressController.NginxIngressController( nginxValues );
g
You can export the variable separately from assignment with a
let
. I did that in this example: https://github.com/pulumi/examples/blob/master/kubernetes-ts-multicloud/index.ts#L48-L63
So you could have the actual creation inside the conditional
c
🙏
and the variable would be initialized as
undefined
?
c
and the variable would be initialized as
undefined
?
You could also do
let x: SomeType | undefined
that allows
x
to be undefined sometimes. But that means, wherever you use
x
, you will need to make sure that it is not
undefined
before you use it.
c
ok - it looks like I can just declare it like :`export let nginx:ingressController.NginxIngressController;`
and conditionally set it later
Working well - thanks!!