@here Hi, I am new to pulumi can someone kindly le...
# general
t
@here Hi, I am new to pulumi can someone kindly let me know how to add a list to config? is it something like
pulumi config set addressSpaces ['xx.xx.xx.xx/ab','yy.yy.yy.yy/cd']
?
r
It is! Have you tried it? With the Node.JS SDK you can load the object with
new Config('<project-name>').requireObject('addressSpaces')
. The only caveat is, that it has to be valid JSON for this to work
g
We don’t currently support list types as configuration values. You can achieve the same thing though by storing a comma delimited value and splitting the value in your pulumi application. We have https://github.com/pulumi/pulumi/issues/2306 to track adding list and map support.
r
I just tested it and it does actually work since
getObject
/
requireObject
just uses
JSON#parse
under the hood (https://github.com/pulumi/pulumi/blob/375b75be84a4073adf939d0e3001229e4f3f4679/sdk/nodejs/config.ts#L133). If I run
pulumi config set addressSpaces '["xx.xx.xx.xx/ab","yy.yy.yy.yy/cd"]'
to set the config value and run
pulumi up
with the following `index.ts`:
Copy code
import * as pulumi from "@pulumi/pulumi";
(new pulumi.Config("test").getObject("addressSpaces") as string[]).forEach(
  addr => {
    console.log(`Address: ${addr}`);
  }
);
it outputs as you would expect
Copy code
test$ pulumi up
Previewing update (dev):

     Type                 Name      Plan       Info
 +   pulumi:pulumi:Stack  test-dev  create     2 messages
 
Diagnostics:
  pulumi:pulumi:Stack (test-dev):
    Address: xx.xx.xx.xx/ab
    Address: yy.yy.yy.yy/cd
 
Resources:
    + 1 to create
But of course I only tested it with the Typescript SDK. It might be different for the other ones?!
t
Thanks Arne, for the solution. I followed a similar path. but used config.require("vnetAddressSpace").split(',');