Search code examples
pulumi

pulumi retrieve an object or array of configs stored


When making a call to new pulumi.Config('someName') I would like to get an array of secrets that are under someName:aValue.

I've tried to call something like const cfg = new pulumi.Config('someName'), but after that, all the mothods under that class all call for a key (e.g. aValue), but that isn't helpful when wanting all secrets under the logical name.

pulumi.*.yaml

  someName:someValue1:
    secure: someSecureValue
  someName:someValue2:
    secure: someOtherSecureValue

somefile.ts

const cfg = new pulumi.Config('someName')

With the given code above, I'm looking for a list of all secrets under someName.


Solution

  • From the docs:

    Configuration values are always stored as strings, but can be parsed as richly typed values.

    For richer structured data, the config.getObject method can be used to parse JSON values.

    For secret values, there are functions getSecretObject() and requireSecretObject(). For your example, you would do something like

    pulumi config set --secret someName '{"someValue1": "someSecureValue", "someValue2": "someOtherSecureValue" }'
    

    and then read it with

    const config = new pulumi.Config();
    const someName = config.requireSecretObject("someName");
    const someValue1 = someName.someValue1;
    

    Obviously, you could also use multiple secrets as separate keys in the config file and retrieve them one-by-one with separate requireSecretObject calls.

    An array would be configured as

    pulumi config set --secret someName '["someSecureValue", "someOtherSecureValue"]'