CircleCI-Public / aws-ecs-orb

An orb that simplifies deployment to Amazon's Elastic Container Service (ECS). Supports both EC2 and Fargate launch types.
https://circleci.com/orbs/registry/orb/circleci/aws-ecs
MIT License
51 stars 80 forks source link

Variable interpolation in overrides JSON #160

Closed nford closed 2 years ago

nford commented 2 years ago

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:

jeffreymlewis commented 2 years ago

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

brivu commented 2 years ago

@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

jeffreymlewis commented 2 years ago

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