Skip to main content

Get possible reserved instances in a subscription by region

Below is a little script that returns all possible reserved instances in a region for a subscription

Prerequisites:

  • Be connected to AZ via an “az login” command
  • The script takes for argument the target subscription id for which we want the possible reservations

The script lists the possible reserved instances in a subscription by first listing the available regions for a subscription then looping through them to get the possible instance reservations.

To run the script:

  • Create a file possible-reserved-instances.sh and copy in it below code:

 

 #!/bin/bash
 SUBSCRIPTION_ID=$1
 
 az account set -s "$SUBSCRIPTION_ID"
 az account list-locations --query "[].{Name:name}" -o table>regions-list
 sed -i -e '1,2d' regions-list
 while read REGION; do
   echo 'Reservations for region "'"$REGION"'" are available in ./regions/'"$REGION"
   az reservations catalog show --reserved-resource-type "VirtualMachines" --location "$REGION"  --subscription-id "$SUBSCRIPTION_ID" > output.json --only-show-errors>./regions/"$REGION"
 done 
  • Add relevant permissions to run the script
chmod +x possible-reserved-instances.sh
  • Launch script
./test-reserved.sh xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Close Menu

WHERE TO FIND US


PARIS

Bâtiment Crisco Duo
7 avenue de la Cristallerie
92310 Sèvres, France

NANTES

Centre d’affaires Euptouyou
4 rue Edith Piaf Immeuble Asturia C
44800 Saint-Herblain, France

PHONE

+33 1 46 48 26 00

EMAIL

[email protected]