https://pulumi.com logo
Title
c

crooked-jelly-50877

09/11/2019, 8:42 PM
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

gorgeous-egg-16927

09/11/2019, 8:51 PM
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

crooked-jelly-50877

09/11/2019, 8:51 PM
🙏
and the variable would be initialized as
undefined
?
c

clever-sunset-76585

09/11/2019, 8:57 PM
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

crooked-jelly-50877

09/11/2019, 8:58 PM
ok - it looks like I can just declare it like :`export let nginx:ingressController.NginxIngressController;`
and conditionally set it later
Working well - thanks!!