convert JSON values to ENV VAR
This is a trick that @eddiewebb finds handy to converry Hashicorp CLI responses into local environment variables that can be used in subequent commands (docker login,etc)
- an image with
jq
(all CCI images have it) - JSON respresenting values to convert to ENV VARs
We basically use jq
as a rudimentary templating engine, converting existing k/v to shell format.
{
"data":
{
"username":"agent_007",
"password":"SuperSocks",
"pin": "0000"
}
}
export AGENT_USERNAME='agent_007'
export AGENT_PASSWORD='SuperSocks'
export AGENT_PIN='0000'
jq -r '.data | to_entries[] | "export AGENT_"+(.key | ascii_upcase)+"="+(.value | @sh)' >> $BASH_ENV
source $BASH_ENV # only if needed in this step, evrry future step will load for us