I'm trying to get the values of tenants in below yaml file using yq. The intent is to dynamically fetch the value depending on env variable.
Let's assume there's an env variable var="az-dev"
, then tenants of az-dev should be retrieved.
I have given some tries as mentioned below but no luck.
YAML file
tenantlist:
az-dev:
tenants:
- myazdev
az-stage:
tenants:
- myazstg1 myazstg2
aw-dev:
tenants:
- myawdev1 myawdev2
aw-stage:
tenants:
- myawstg1 myawstg2
Tries:
var="az-dev" yq e '.tenantlist | select(. == env(var))' file.txt
var=az-dev; yq '.tenantlist |= strenv(var) has("az-dev")' file.txt
Any help would be appreciated. TIA.