CREATING A VIRTUAL MACHINE USING AZURE CLI
Tags: beginners, azure, virtualmachine, tutorial
Published: 2024-06-25 16:23:25

We already established that there are several routes that can be taken to achieve the deployment of resources and services on Azure. 
For today, I will be using the Azure Command Line Interface (CLI) to create a virtual machine on Azure.

## **PREREQUISITE**
- Working computer
- Internet connection
- Microsoft Azure account + active subscription
- PowerShell application

## **PROCEDURE**
### **INSTALL AZURE CLI**
Regardless of which OS runs on your computer, click on this link (https://learn.microsoft.com/en-us/cli/azure/) to get guidelines on how to set up Azure CLI on your computer.

### **CONNECT TO AZURE ACCOUNT**
To achieve this, type in this command `az login` in the command line interface.
You either have a sign-in webpage or a sign-in pop-up window appearing on your screen after entering that command.
Select the Azure account you want to log in with and click on “Continue” as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/666g50oq33g9dns2ezcx.png)

A list of available subscriptions you have and their respective IDs will be generated.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjas6s95w6nrktkj9oiz.png)

Select the one you require following the onscreen instruction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vstz2xz325kczute4sel.png)


### **CREATE A RESOURCE GROUP**
Create a resource group by entering a command in the interface following the format below:
`az group create --name **resourcegroupname** --location **regionname**`
_NB: The asterisked sections are to be customised to suit your requirements._
A message informing users of the success will be displayed on the following lines.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s46mr5f0qifkeyi6hiae.png)

The newly created resource group can also be located on the Azure portal for further verification.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xeplavmfydzn3u3vpz11.png)


### **CREATE A VIRTUAL MACHINE**
In a manner similar to how a resource group was created, a virtual machine can also be created but in this case, providing more specifications as we would on the Azure portal when creating a VM.
Enter a command in the CLI following the format below:
`az vm create --resource-group **resourcegroupname** --name **vmname** --image operatingsystemname --admin-username username --admin-password '**password0!**' --size **vmsize** --subnet **subnetname** --vnet-name **vnetname** --nsg **nsgname** --no-wait`
_NB: The asterisked sections are to be customised to suit your requirements._

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvrm1zmd4lzwmjbiqbky.png)

The created VM can be located on the Azure portal for further verification.
Open the VM resource on the portal.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj0lfyl04mu8w36svhmb.png)

On the VM page, click on “Settings” and then, “Advisor recommendations” to see if  the VM and other resources are not running at optimal states.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywzhecovbxhoayr9g0ki.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixgabq6nb7wrvz372iwg.png)