Reputation: 3803
Using yq (v4.25.3), and considering the following yaml file
accounts:
- account_id: 'XXXXXXXX'
name: sandbox
deploy_iam: true
role: arn:aws:iam::XXXXXXXX:role/iam_role
regions:
- all
- account_id: 'YYYYYYY'
name: dev
deploy_iam: true
role: arn:aws:iam::YYYYYYY:role/iam_role
regions:
- all
Is it possible to get the value of the deploy_iam
attribute given an account_id
value?
I can get the list of account_id with
yq '.accounts[].account_id' < accounts.yml
And I tried to filter using with_entries
yq '.accounts[].account_id |= with_entries(select(.key == "XXXXXXXX"))' < accounts.yml
Without luck so far.
Any idea?
Upvotes: 0
Views: 2354
Reputation: 85780
With mikfarah/yq it should be pretty straightforward. Select the required object with the select()
expression and access the required field with the dot notation
yq '.accounts[] | select(.account_id == "XXXXXXXX").deploy_iam' < accounts.yml
Upvotes: 1