-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: set default availability zones to null and find azs that suppor…
…t the instance type
- Loading branch information
1 parent
9ed24d8
commit 6c14225
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#! /usr/bin/env bash | ||
|
||
# Given a Azure VM instance type and a region return the availability zones that support the instance type | ||
|
||
# Example: | ||
# ./vmtype_to_az.sh Standard_D2_v3 westeurope | ||
# | ||
# Output: | ||
# ["1", "2", "3"] | ||
|
||
# Copy script arguments to named environment variables | ||
VM_TYPE="$1" | ||
REGION="$2" | ||
|
||
# Check if both arguments are provided | ||
if [ -z "$VM_TYPE" ] || [ -z "$REGION" ]; then | ||
echo "Error: Both VM type and region must be provided." >&2 | ||
echo "Usage: $0 <vm_type> <region>" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Query Azure CLI for availability zones in the region for the specified VM type | ||
ZONES=$(az vm list-skus --location "$REGION" --size "$VM_TYPE" --query "[0].locationInfo[0].zones" -o json | jq -r -c 'sort | .[0:3]') | ||
|
||
# Check if the query returned any results | ||
if [ -z "$ZONES" ] || [ "$ZONES" == "null" ]; then | ||
echo "Error: No availability zones found for VM type $VM_TYPE in region $REGION." >&2 | ||
exit 1 | ||
fi | ||
|
||
# Output the result | ||
jq -n --arg zones "$ZONES" '{"zones":$zones}' |