pulumi icon indicating copy to clipboard operation
pulumi copied to clipboard

How to set a list of strings for a key in config-map

Open jalmeroth opened this issue 3 years ago • 5 comments

Howdy! I'm trying to find a way to set a list of strings for a key via the pulumi/actions config-map property. This is a follow-up on the discussion in Slack.

I tried to set it with: "some-key":{"value":["some-value-a","some-value-b"]} which leads to a comma-separated string some-value-a,some-value-b in the Pulumi.stack.yaml.

I also tried to send: {"some-other-key":[{"value":"some-other-value-a"},{"value":"some-other-value-b"}]} which leads to a string undefined in the Pulumi.stack.yaml.

What I would like to see is:

<pulumi-project>:some-key:
  - some-value-a
  - some-value-b

This could be defined via cli with pulumi config set --path "some-key[0]" "some-value-a" but how do you do it via automation api?

jalmeroth avatar Dec 14 '22 07:12 jalmeroth

@jalmeroth thanks for reporting this. If I have this right, you have an @pulumi/actions job like so:

      - uses: pulumi/actions@v3
        with:
          config-map:
            some-key:
              value: 
                - some-value-a
                - some-value-b

And when the program runs, this is being turned into a string, or something like that?

AaronFriel avatar Dec 14 '22 19:12 AaronFriel

@jalmeroth thanks for reporting this. If I have this right, you have an @pulumi/actions job like so:

      - uses: pulumi/actions@v3
        with:
          config-map:
            some-key:
              value: 
                - some-value-a
                - some-value-b

And when the program runs, this is being turned into a string, or something like that?

@AaronFriel thanks for digging into this.

No, I think one needs to provide a string here, otherwise it breaks the GH Workflow syntax.

What we provide looks like this:

- uses: pulumi/actions@v3
  with:
    config-map: "some-key": {"value": ["some-value-a", "some-value-b"]}
  "some-other-key": [{"value": "some-other-value-a"}, {"value": "some-other-value-b"}]

jalmeroth avatar Dec 14 '22 20:12 jalmeroth

Ha, I finally found it! The problematic code is here.

This line uses Template literals to convert the list of strings into a comma-seperated str:

args = [...args, secretArg, `${key}=${value.value}`];

I'm not into Typescript at all, but I wrote some pseudo-code that could fix the issue:

    async setAllConfig(stackName: string, config: ConfigMap): Promise<void> {
        let args = ["config", "set-all", "--stack", stackName];
        for (const [key, value] of Object.entries(config)) {
            const secretArg = value.secret ? "--secret" : "--plaintext";
            if (Array.isArray(value.value)) {
                args = [...args, "--path"];
                value.value.forEach((value, index) => {
                    args = [...args, secretArg, `"${key}[${index}]"=${value}`];
                });
            } else {
                args = [...args, secretArg, `${key}=${value.value}`];
            }
        }

        await this.runPulumiCmd(args);
    }

jalmeroth avatar Dec 20 '22 23:12 jalmeroth

@AaronFriel could you please review this issue and/or remove the awaiting-feedback label. Thank you!

jalmeroth avatar Jan 02 '23 08:01 jalmeroth

Hello 👋 any updates on this? Currently, we're able to work around this issue by using comma-separated string, but it would be great to be able to pass in an actual array to the config-map.

      - uses: pulumi/actions@v5
        with:
          command: up
          upsert: true
          config-map: "{ ConfigKeyName: { value: "configValue1,configValue2,configValue3", secret: false } }"

c-brooks avatar Jun 17 '24 17:06 c-brooks