Skip to content

Instantly share code, notes, and snippets.

@sebnyberg
Created June 20, 2024 19:17
Show Gist options
  • Save sebnyberg/a02cee55b2979949ffb0bd9b4f93f490 to your computer and use it in GitHub Desktop.
Save sebnyberg/a02cee55b2979949ffb0bd9b4f93f490 to your computer and use it in GitHub Desktop.
Azure stuff
#!/usr/bin/env bash
#
# findskus.sh - Find SKUs that support disk encryption, ephemeral disk, and
# have at least two availability zones.
#
# Usage: findskus.sh [memoryGB] [location]
#
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "Usage: $0 [memoryGB] [location]" >&2
echo "Example: $0 16 southcentralus" >&2
exit 1
fi
if ! command -v jq &> /dev/null; then
echo "This script requires jq. Please install it and try again." >&2
exit 1
fi
memgb=${1}
location=${2}
echo "Finding SKUs with ${memgb}GB memory, ephemeral disk, disk encryption,"
echo "and at least two availability zones in ${location}..."
az vm list-skus -l "${location}" -o json \
| jq --arg memoryGB "${memgb}" '.[] | select(
(.capabilities | length > 0) and
(.capabilities[] | select(.name == "MemoryGB" and .value == $memoryGB )) and
(.capabilities[] | select(.name == "EphemeralOSDiskSupported" and .value == "True")) and
(.capabilities[] | select(.name == "EncryptionAtHostSupported" and .value == "True")) and
(.locationInfo[].zones | length >= 2) and
(.restrictions[].restrictionInfo.zones | length <= 1)
) | {
"zones": .locationInfo[].zones,
"restrictedZones": .restrictions[].restrictionInfo.zones,
"size": .size,
"cpuKind": (.capabilities[] | select(.name == "CpuArchitectureType" ) | .value ),
"vCPUs": (.capabilities[] | select(.name == "vCPUs" ) | .value ),
"memoryGB": (.capabilities[] | select(.name == "MemoryGB" ) | .value )
}'
@sebnyberg
Copy link
Author

# find role assignments whose identities no longer exist
az role assignment list --all -o tsv --query "[?principalName == '']"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment