DevOps for Azure configuration and deployment is a key component of cloud operations management without having the need to use the Azure user interface. When there are multiple subscriptions to manage, we need to make sure that we first select the correct subscription from Azure. We can take a look at how this can be done using Azure CLI 2.0 (install from this site).
After opening the Bash command shell, follow these steps:
Login to Azure
We can login to our Azure account using the login command. This requires some browser interaction to enter a code for the two factor authentication.
az login
|
List Our Subscriptions
After a successful login, we can list all of our current subscription using the account command.
az account –list –all –output table
|
We can see the returning JSON with a list of accounts that are available in a nice table format. Each reference has a name and isDefault property. Only one of them is our default subscription.
Set a Default Subscription
We can change our default subscription by running the account set command.
az account set --subscription “my subscription name”
|
Validate Default Subscription
We should be able to list all the subscriptions again and verify that the default subscription is correct by filtering the results using GREP. (Note this work when using Bash)
az account –list –all –output table | grep “True”
|
The result should be only the subscription that is set to IsDefault = true.
At this point, we should be on the right subscription, and we can move forward with any additional configuration using Azure CLI.