Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable interpolation in overrides JSON #160

Closed
nford opened this issue May 25, 2022 · 3 comments · Fixed by #165
Closed

Variable interpolation in overrides JSON #160

nford opened this issue May 25, 2022 · 3 comments · Fixed by #165
Assignees
Labels
bug Something isn't working

Comments

@nford
Copy link

nford commented May 25, 2022

Orb version:

2.2.1

What happened:

...
environment:
      CLUSTER_NAME: foo-cluster
      CONTAINER_NAME: rails
    steps:
      - aws-cli/install
      - aws-authenticate
      - run:
          command: |
            aws sts get-caller-identity
- aws-ecs/run-task:
          cluster: '${CLUSTER_NAME}'
          overrides: '{"containerOverrides":[{"name": "${CONTAINER_NAME}", "environment": [{"name": "RUN_DB_MIGRATIONS","value": "true"}]}]}' 
...

An error occurred (InvalidParameterException) when calling the RunTask operation: name must match ^[a-zA-Z0-9\-_]+$

The same ENV VAR is used elsewhere without issue. If I replace ${CONTAINER_NAME} with the relevant string it works without issue. The Orb does not seem to interpolate the value within this JSON.

Expected behavior:

name value should be populated

Additional Information:

@nford nford added the bug Something isn't working label May 25, 2022
@jeffreymlewis
Copy link

I ran into this exact issue today. Are you already working on a PR? If not I'll submit something.

@brivu
Copy link
Contributor

brivu commented Jun 3, 2022

@jeffreymlewis,

I've been working on this all day to figure it out but it seems like doing a eval echo on the overrides parameter is causing more issues, even without expanding an environment variable within the json. Here's the error I am getting when trying to run do so:

Error parsing parameter '--overrides': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
JSON received: {containerOverrides:[{name: sleep, memory: 512}]}

I'll be checking in with my team to see if there's any workarounds but if you can think of one, feel free to let me know.

Best,
Brian

@brivu brivu self-assigned this Jun 3, 2022
@jeffreymlewis
Copy link

Escaping the double-quotes would work, but it's ugly and makes this a breaking change. 🙁

Sorry I can't be more help. Unfortunately I couldn't use this orb in my current project (for other reasons) and never fully implemented this solution.

Here's how I was testing variable expansion.

#!/bin/bash

json='{\"containerOverrides\":[{\"name\": \"${CONTAINER_NAME}\", \"environment\": [{\"name\": \"RUN_DB_MIGRATIONS\",\"value\": \"true\"}]}]}'

json_eval=$(eval echo \"$json\")

echo $json_eval

@brivu brivu linked a pull request Jun 7, 2022 that will close this issue
@brivu brivu closed this as completed in #165 Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants