allan

jq Recipes

May 29th, 2023 (edited)
382
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Markdown 0.92 KB | Software | 0 0

jq Recipes

Azure

Copy Tags From src to dst resource-id
Ref: https://github.com/Azure/azure-cli/issues/13170#issuecomment-629005051

IFS=','
TAGS=($(az tag list --output json --resource-id <resource-id-src> | \
  jq -r '.properties.tags|to_entries|map("\(.key)=\(.value|tostring)")|join(",")'))
az tag create --resource-id <resource-id-dst> --tags ${TAGS[@]}
IFS=' '

List the ID of Every Resource in a Group
az resource list --resource-group <rg-name> | jq -r '"\(.[].id)"'

Perform Action on Every ID in a Group
while read id; do <az action>; done <<<$(az resource list --resource-group <rg-name> | jq -r '"\(.[].id)"')

List the Name, Type and ID of Resources in a Group
az resource list --resource-group <rg-name> | jq 'map({name,type,id})'

List All Public IP Address Resources in a Tenant
az resource list | jq 'map(select(.type|endswith("publicIPAddresses"))|{name,type,id})'

Tags: JQ
Comments
  • User was banned
Add Comment
Please, Sign In to add comment