Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created September 8, 2022 09:06
Show Gist options
  • Save chgeuer/20241f1242625eeba63af878440d3c74 to your computer and use it in GitHub Desktop.
Save chgeuer/20241f1242625eeba63af878440d3c74 to your computer and use it in GitHub Desktop.
#!/bin/bash
access_token="$( az account get-access-token --resource-type arm | jq -r '.accessToken' )"
# echo "${access_token}" | jq -R 'split(".")|.[1]|@base64d|fromjson'
subscriptionId="706df49f-998b-40ec-aed3-7f0ce9c67759"
# IFS='' read -r -d '' azureResourceGraphQuery <<'EOF'
# SpotResources
# | where type =~ 'microsoft.compute/skuspotpricehistory/ostype/location'
# | where sku.name in~ ('standard_d2s_v4', 'standard_d4s_v4')
# | where properties.osType =~ 'linux'
# | where location in~ ('eastus','southcentralus')
# | project skuName=tostring(sku.name), osType=tostring(properties.osType), location, latestSpotPriceUSD=todouble(properties.spotPrices[0].priceUSD)
# | order by latestSpotPriceUSD asc
# EOF
azureResourceGraphQuery="project id, name, type, location, tags"
body="$( echo "{ \"subscriptions\": [ \"${subscriptionId}\" ], \"options\": {\"\$top\": 100, \"\$skip\": 0, \"resultFormat\": \"objectArray\", \"allowPartialScopes\": false} }" \
| jq --arg x "${azureResourceGraphQuery}" '.query=$x' )"
curl \
--include \
--request POST \
--url "https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2020-04-01-preview" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${access_token}" \
--data "${body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment