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
--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
bashCopyEditaz vm create \
--resource-group myResourceGroup \
--name myWindowsVM \
--image Win2019Datacenter \
--admin-username azureuser \
--admin-password YourP@ssword123
โ ๏ธ Tip: Passwords must meet Azureโs complexity requirements!
๐ 5.2 Connect to the VM
Get the public IP address of the VM:
bashCopyEditaz vm list-ip-addresses --name myLinuxVM --output table
Connect to a Linux VM:
bashCopyEditssh azureuser@<public-ip-address>
Connect to a Windows VM (RDP):
Open Remote Desktop Connection.
Enter the public IP.
Login with the username/password.
โ Now you're inside your VM!
๐ 5.3 Managing a VM (Start, Stop, Restart, Delete)
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
bashCopyEditaz storage account create \
--name mystorageaccount123 \
--resource-group myResourceGroup \
--location eastus \
--sku Standard_LRS
--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
bashCopyEditaz storage account list --output table
Delete a Storage Account
bashCopyEditaz storage account delete --name mystorageaccount123 --resource-group myResourceGroup
๐ 5.5 Creating Basic Networking Components
๐ ๏ธ Create a Virtual Network (VNet)
bashCopyEditaz network vnet create \
--resource-group myResourceGroup \
--name myVNet \
--address-prefix 10.0.0.0/16 \
--subnet-name mySubnet \
--subnet-prefix 10.0.1.0/24
โ This creates a VNet and a Subnet at the same time.
๐ก๏ธ Create a Network Security Group (NSG)
bashCopyEditaz network nsg create \
--resource-group myResourceGroup \
--name myNSG
NSG controls inbound/outbound traffic to resources like VMs.
๐ก๏ธ Create an NSG Rule to Allow SSH (Linux VM)
bashCopyEditaz network nsg rule create \
--resource-group myResourceGroup \
--nsg-name myNSG \
--name allow-ssh \
--protocol Tcp \
--direction Inbound \
--priority 1000 \
--source-address-prefixes '*' \
--source-port-ranges '*' \
--destination-address-prefixes '*' \
--destination-port-ranges 22 \
--access Allow
โ 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:
bashCopyEditaz group delete --name myResourceGroup
โ This deletes the VMs, Storage Accounts, VNets, everything inside the group.
๐ Module 5 Summary
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