Azure CLI
Azure CLI is a set of commands used to create and manage Azure resources.
To start off, run the following command to display all available commands.
$ az --help
To display available subcommands add --help
after any command.
$ az login --help
Use the find
command to fetch examples of use for commands.
az find "az login"
Login
To login to Azure run the following command:
$ az login
To sign in with a service principal run the following command:
$ az login --service-principal -u <CLIENT_ID> -p <CLIENT_SECRET> --tenant <TENANT_ID>
If you have multiple tenants it can be useful to login to different tenants in each terminal window. This can be achieved with the --use-device-code
argument. See Azure docs.
$ az login --use-device-code --tenant <TENANT_ID>
Automated tests
In a CI/CD environment Azure CLI could be used to automate several tasks. For example running pre flight checks before further pipelines are executed. Several Azure resources allow us to verify name is not in use already.
$ az acr check-name --name tests
{
"message": "The registry tests is already in use.",
"nameAvailable": false,
"reason": "AlreadyExists"
}
$ az storage account check-name --name test
{
"message": "The storage account named test is already taken.",
"nameAvailable": false,
"reason": "AlreadyExists"
}
No comments