Shell scripts to fetch the quota information for the Compute, Network and Storage resources for the desired subscriptions in Microsoft Azure.
The quota information is all about how much resources are allocated for a subscription and how much of those resources are being actually used. This helps one to plan their deployments.
There are in all 2 shell scripts which help to fetch the quota information as follows:
azquotaworker.sh: This is the script which does the actual work of fetching the quota information for a subscription.
azquotamaster.sh: This is the script which feeds the parameters to the azquotaworker.sh and then executes it.
Only the azquotamaster.sh is to be modified with the relevant details.
azquotaworker.sh just does the work of fetching the data.
Both the shell scripts are to be copied to the same directory and are to be made executable. The quota information is generated as a .csv per subscription per region. The csv file naming will be of the format <Subscription_id>_.csv
az-cli is needed for the scripts to work -- https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
Step a:
To use azquotamaster.sh, an Azure Active Directory service principal is to be created -- https://docs.microsoft.com/en-us/cli/azure/ad/sp?view=azure-cli-latest#az-ad-sp-create-for-rbac .
The default command for the same is:
az ad sp create-for-rbac -n "<sp_name>"
The above command gives the below output:
{
"appId": "",
"displayName": "<sp_name>",
"name": "http://<sp_name>",
"password": "<sp_password>",
"tenant": "<tenant_id>"
}
Step b:
Copy azquotamaster.sh and azquotaworker.sh in the same directory. Now based on the output received above, the azquotamaster.sh needs to be modified as follows:
Step b.1:
Enter the regions for which the quota information is to be fetched. Example as below:
regionarr=('southeastasia' 'eastus')
Step b.2:
Enter the AAD service principal details based on the output obtained in step a. Example as below:
./azquotaworker.sh "http://myspname" "my_sp_password" "tenant_id" "subscription_id" "${regionarr[@]}"
So in all the 2 lines should look as below:
regionarr=('region1' 'region2')
./azquotaworker.sh "<sp_name>" "<sp_password>" "<tenant_id>" "<subscription_id>" "${regionarr[@]}"
Repeat the above two lines with relevant details for fetching the quota information for different subscription ids.
Step c: Make both the shell scripts executable (azquotamaster.sh and azquotaworker.sh)
Step d:
Execute the azquotamaster.sh script. Example below if the script is to be execute from the same folder:
./azquotamaster.sh
Step e: The quota information is generated in the .csv files. The csv file naming will be of the format <Subscription_id>_.csv