garden icon indicating copy to clipboard operation
garden copied to clipboard

0.13: [Bug]: ConfigTemplate fun: using $forEach in variables results in error

Open chrispsplash opened this issue 2 years ago • 0 comments

Garden Bonsai (0.13) Bug

Current Behavior

Create a ConfigTemplate that attemps to use $forEach to construct an item under variables and get Invalid template string error!

kind: ConfigTemplate
name: foobar
inputsSchemaPath: foobar.schema.json

configs:
  - kind: Run
    type: exec
    name: ${parent.name}

    variables:
      decorateWords:
        $forEach: ${inputs.someWords}
        $return: '"${item.value}" is at index ${item.key}'

    spec:
      command:
        - echo
        - ${jsonEncode(var.decorateWords)}

Expected behavior

The Run action should print out the JSON string representing var.decorateWords. For example:

["\"alef\" is at index 0", "\"bet\" is at index 1", "\"gimel\" is at index 2"]

Reproducible example

Here is a repo demonstrating the issue. Just clone and run garden run baz. Here's sample output:

❯ garden run baz
Run 🏃‍♂️

Garden v0.13 (Bonsai) is a major release with significant changes. Please help us improve it by reporting any issues/bugs here:
https://go.garden.io/report-bonsai
→ Run garden util hide-warning 0.13-bonsai to disable this warning.
ℹ garden               → Running in Garden environment default.default
ℹ providers            → Getting status...
✔ providers            → Cached (took 0.7 sec)
ℹ providers            → Run with --force-refresh to force a refresh of provider statuses.
ℹ graph                → Resolving actions and modules...
✔ graph                → Done (took 0.1 sec)
✖ run.baz              → Failed processing resolve Run type=exec name=baz (took 0.01 sec). This is what happened:

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Invalid template string ({"$forEach":"zero,one,two,three,fo…): Could not find key item. Available keys: actions, command, datetime, environment, git, inputs, local, modules, parent, project, providers, runtime, secrets, template, this, var and variables.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 test action(s) failed!

See .garden/error.log for detailed error message

Workaround

I couldn't find one. I'm currently using a short python script to generate the values.

Suggested solution(s)

N/A

Additional context

N/A

Your environment

  • OS: macOS Ventura 13.5.2
  • How I'm running Kubernetes: N/A
❯ garden version
garden version: 0.13.17

chrispsplash avatar Oct 06 '23 15:10 chrispsplash