Are you managing some of your workloads on Azure Cloud and want to automate your management tasks using scripting and or command line? Azure Command Line from MacOS, is that possible? If yes, how do I get started?
My work on a project that required access and connection from anywhere to anywhere, with several users sharing the same infrastructure, lead me to use Microsoft Azure Cloud. My first task on the project was to build the infrastructure for the VMs. I implemented following steps to reduce costs:
- VMs without public IP addresses;
- Use of VeeamPN for VPN connections;
- Power-Off the VMs at 7:00 PM; and
- Power-On the VMs at 6:00 AM.
Turning off the VMs at 7:00 PM is a simple task; Auto-Shutdown is a built-in option in the Azure Cloud product. My challenge was to automatically switch on my environment at 6:00 AM to be ready for the day, without using the available Azure Tasks.
To add to the above task requirements, my desktop machine is an Apple iMac. What are my options?
To make my task easier, Microsoft has thought about the Apple MacOS users. All I need is Microsoft Azure Command Line Interface (CLI) for Apple Mac. The CLI is deployed with the following commands:
Installing Azure CLI
Installing the Azure CLI on the Apple Mac is a very simple task; I run an Apple MacOS Terminal session, and then type the following command:
curl -L https:
//aka
.ms
/InstallAzureCli
|
bash
After answering several questions about the location of the default CLI directories and other configuration items, and upon completion of the installation, the installation process requested a restart of the Shell to begin using the az CLI command:
Login to your Azure Subscription
After the installation completed, and before I can start using the “az” command to initiate the Azure Cloud Tasks, I must login to the Azure account using the “az login” command to authenticate to a URL and code. See the following command:
If there are multiple subscription IDs, I use the following CLI command to select the required ID:
az account set --subscription "SubscriptionName"
Stop/Start Azure VMs
After completing the installation and configuration of the CLI, I am ready to manage Microsoft Azure VMs from my home iMac using the command line. The first two commands that I tried are:
az vm stop -g [resourceGroupName] -n [VmName]
az vm start -g [resourceGroupName] -n [VmName]
Conclusion
I was surprised at the ease of configuration and deployment of the Microsoft Azure CLI on the Apple MacOS. I was prepared for a long day of troubleshooting; but as you can see in this blog post, the steps and the log of the post tell it all. For a reference to the complete Microsoft Azure CLI commands, you can find it at this link:
https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest