Navigating the Microsoft Azure CLI

Navigating the Microsoft Azure CLI

ยท

5 min read

Welcome to the world of Azure Command-Line Interface (CLI)! As cloud computing continues to revolutionize the way we build, deploy, and manage applications, having a powerful and efficient tool like the Azure CLI in your toolkit is essential.

Before we step ahead! We should be aware of some the knowledge about CLI? Obv, being as a developer, we are a fan of handling and managing commands.

So here we go,
A Command-Line Interface (CLI) is a text-based interface that allows users to interact with a computer system or software by typing commands directly into a terminal or command prompt. Unlike graphical user interfaces (GUIs), which rely on visual elements like buttons and menus, CLIs operate purely through text-based commands.

But why is the CLI important?

NMW, here are some listed reasons:

  1. Efficiency and Speed: The Azure CLI allows rapid execution of tasks through concise commands, saving time and effort.

  2. Automation and Scripting: Script repetitive tasks and create consistent processes.

  3. Resource Management: Easily create, update, and delete Azure resources.

  4. Cross-Platform Compatibility: Works seamlessly across Windows, Linux, and macOS.

    Embrace the power of the Azure CLI and command the cloud with confidence! ๐Ÿš€๐Ÿ’ป

But how is the CLI useful to us?

Definetely, you're going good to understand this:

  1. Learning Curve and Mastery: Mastering the CLI enhances your technical skills and empowers you to navigate complex systems.

  2. Troubleshooting and Debugging: CLI output provides detailed information for diagnosing issues.

  3. Cloud Resource Management: Azure CLI streamlines tasks like creating, monitoring, and managing Azure resources.

  4. DevOps Integration: CLI commands seamlessly fit into CI/CD pipelines for automation.

Bit of introduction about Microsoft Azure

Microsoft Azure Logo | Symbol, History, PNG (3840*2160)

Microsoft Azure is a cloud computing platform provided by Microsoft. It allows organizations to build, deploy, and manage applications and services in a flexible and scalable manner.

It includes services such as Compute Services, Storage Services, Networking Services, Databases, AI and Machine Learning, IoT Services, Serverless Computing, Monitoring and Management.

Now here come up with all the resources being provided by Azure. Just go to the portal through link and access your resources.

Hurray! ๐Ÿ™Œ You probably might have created a cute VM, a Virtual Machine and get back to this blog. Now what if I say that go to the portal again and create another one.
Indeed, you will be creating another one through the portal, leaving your code editor and local environment aside.

What if, what if I say that please create another one just to test some of our code. Surely you will be maddened about it since you're leaving your native working environment to create something another. ๐Ÿค”

So here comes, Microsoft Azure CLI, a small CLI tool from Microsoft. Azure CLI is a set of commands that allow you to interact with Azure services via the command line.
It is designed for automation and efficiency, enabling you to work quickly with Azure resources. โŒจ๏ธ

So, let's have a quick walkthrough on accessing Azure resources through command line.

Firstly, let's install the CLI through the instructions, in this blog I'm using Linux Mint, based on Ubuntu so go ahead according to your OS. Use this link to download.

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Using cURL, we are downloading a script that is maintained by Azure CLI Team. This script runs all installation commands in one step.

Now, login in to command line with the Azure account you're holding with. This method is known as signing in interactively.

az login

Tip: Keep your Azure Account signed in on your default browser. This will help to smoothly login into your tenant.

Now, let's move forward with creating resource and virtual machine through the command line itself.

First of all setup your subscription ID which helps the CLI to gain access to those resources which are available to you.

az account set --subscription <subscription_id>

Subscription ID is available under the Subscription coloumn on Azure Portal. Just search the keyword subscription, and you will get it.

Now heading towards creating a simple and very simple Resource Group.

A Resource Group in Azure is nothing but a logical container where you are creating your Azure resources. That holds all your Azure Resources. A resource group created in a specific region can contain the resources created in the other regions. There is no restriction on that.

resourcegroup="myResourceGroupCLI"
location="westus3"
az group create --name $resourcegroup --location $location

Woof! You're done creating a resource group on your cloud. Step ahead with creating a Virtual Machine Quickly.

Here, we will create a VM named myVM with the username as tauqeerops

vmname="myVM"
username="tauqeerops"
resourcegroup="myResourceGroupCLI"
az vm create \
    --resource-group $resourcegroup \
    --name $vmname \
    --image Ubuntu2204 \
    --public-ip-sku Standard \
    --admin-username $username

Let's take a glimpse on the Azure Portal whether our Instance (or say VM) with RG has been created or not?

Yayyyy!! Here you can see our Resource Group named myResourceGroupCLI has been created. ๐ŸŽ‰

See, how we we are going good. Our Virtual Machine named myVM has been created and working properly. ๐Ÿฅณ

Gosshhh! We're on billing, we should be stopping it when not working on it.

vmname="myVM"
az vm stop --resource-group myResourceGroupCLI --name $vmname

Let's delete it to avoid any unwanted bill.

vmname="myVM"
az vm delete --resource-group myResourceGroupCLI --name $vmname

So in this walkthrough, we have created resource groups, made VM on top of that, stopped and deleted it when not required or not in use.

Though we can use Azure CLI for various purpose including Listing Resources, Managing Network Settings, Create and Manage Azure App Service Web Apps, or Working with Azure Key Vault.

Useful resources:

Docs by Microsoft Azure Team for Azure CLI: https://learn.microsoft.com/en-us/azure/virtual-machines/

Get Azure Credits through free account: https://azure.microsoft.com/en-us/free/

Get Visual Studio Enterprise subscription for Azure Credits: https://visualstudio.microsoft.com/subscriptions/

Go for Microsoft for Startups that can help you gain AZ Credits: https://www.microsoft.com/en-in/startups

Azure for students: https://azure.microsoft.com/en-in/free/students/

ย