Creating and Managing Resources with Azure CLI

5.1 Creating Virtual Machines (VMs)

Virtual Machines (VMs) are one of the most common resources you'll deploy in Azure.


πŸ› οΈ Create a Linux VM

bashCopyEditaz vm create \
  --resource-group myResourceGroup \
  --name myLinuxVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys
Parameter
Purpose

--resource-group

Where the VM will be created

--name

Name of the VM

--image

OS image (Ubuntu, Windows, etc.)

--admin-username

Login username

--generate-ssh-keys

Automatically create SSH keys

βœ… This command will create:

  • VM

  • Public IP

  • NIC (Network Interface)

  • OS Disk

  • Virtual Network (if needed)


πŸ–₯️ Create a Windows VM

⚠️ Tip: Passwords must meet Azure’s complexity requirements!


πŸ”Œ 5.2 Connect to the VM

Get the public IP address of the VM:


Connect to a Linux VM:


Connect to a Windows VM (RDP):

  1. Open Remote Desktop Connection.

  2. Enter the public IP.

  3. Login with the username/password.

βœ… Now you're inside your VM!


πŸ›‘ 5.3 Managing a VM (Start, Stop, Restart, Delete)

Action
Command

Stop a VM

az vm stop --name myVM --resource-group myResourceGroup

Start a VM

az vm start --name myVM --resource-group myResourceGroup

Restart a VM

az vm restart --name myVM --resource-group myResourceGroup

Delete a VM

az vm delete --name myVM --resource-group myResourceGroup

βœ… Important: Stopping a VM does not delete it β€” it just stops billing for compute time (but storage costs remain).


πŸ“¦ 5.4 Creating Storage Accounts

Storage Accounts provide scalable, durable cloud storage for:

  • Blobs

  • Files

  • Tables

  • Queues


πŸ› οΈ Create a Storage Account

Parameter
Purpose

--name

Globally unique name

--resource-group

Where the Storage Account will be created

--location

Azure region

--sku

Storage redundancy options (LRS, GRS)

βœ… Name must be globally unique (only lowercase letters and numbers).


List Storage Accounts


Delete a Storage Account


🌐 5.5 Creating Basic Networking Components


πŸ› οΈ Create a Virtual Network (VNet)

βœ… This creates a VNet and a Subnet at the same time.


πŸ›‘οΈ Create a Network Security Group (NSG)

NSG controls inbound/outbound traffic to resources like VMs.


πŸ›‘οΈ Create an NSG Rule to Allow SSH (Linux VM)

βœ… This opens port 22 (SSH) inbound.


🧹 5.6 Cleaning Up Resources

When you're done, delete the Resource Group to clean up everything inside it:

βœ… This deletes the VMs, Storage Accounts, VNets, everything inside the group.


πŸ“ Module 5 Summary

Topic
Key Points

Create VMs

az vm create

Connect to VMs

SSH (Linux) or RDP (Windows)

Manage VMs

Start, stop, restart, delete

Create Storage Accounts

az storage account create

Create Networking Components

VNet, Subnet, NSG

Clean up Resources

az group delete

Last updated