azlin kill¶
Delete a VM and all associated resources
Description¶
The azlin kill command deletes a VM and all its associated Azure resources: the VM itself, OS disk, network interface, and public IP. This is the quickest way to completely remove a VM from Azure.
Warning: This operation is irreversible. The VM and all data will be permanently deleted.
Usage¶
Arguments¶
| Argument | Description |
|---|---|
VM_NAME | Name of the VM to delete (required) |
Options¶
| Option | Type | Description |
|---|---|---|
--resource-group, --rg TEXT | Name | Azure resource group |
--config PATH | Path | Config file path |
--force | Flag | Skip confirmation prompt |
-h, --help | Flag | Show command help and exit |
Examples¶
Delete with Confirmation¶
Output:
Delete VM: azlin-vm-12345
Resources to delete:
- VM: azlin-vm-12345
- OS Disk: azlin-vm-12345_OsDisk_1234
- NIC: azlin-vm-12345-nic
- Public IP: azlin-vm-12345-ip
Continue? [y/N]: y
Deleting resources...
✓ Deleted VM
✓ Deleted disk
✓ Deleted NIC
✓ Deleted Public IP
VM 'azlin-vm-12345' deleted successfully.
Force Delete (No Confirmation)¶
Delete with Resource Group¶
Delete Multiple VMs¶
# Delete several VMs in sequence
azlin kill vm1 --force
azlin kill vm2 --force
azlin kill vm3 --force
# Or use a loop
for vm in vm1 vm2 vm3; do
azlin kill $vm --force
done
What Gets Deleted¶
The command deletes:
- VM - The virtual machine instance
- OS Disk - Boot disk attached to VM
- Data Disks - Any additional data disks
- Network Interface (NIC) - Network card
- Public IP - Public IP address (if assigned)
- NSG Rules - Network security group rules specific to this VM
NOT deleted: - Resource group (use azlin destroy --delete-rg for that) - Shared resources (VNet, storage accounts, etc.) - SSH keys - Snapshots
Behavior¶
- Validation - Verifies VM exists
- Resource Discovery - Identifies all associated resources
- Confirmation - Prompts user (unless
--force) - Deletion - Deletes resources in order:
- VM first
- Then disk, NIC, and IP in parallel
- Verification - Confirms all resources deleted
Troubleshooting¶
VM Not Found¶
Symptoms: "VM 'NAME' not found"
Solutions:
# List VMs to find correct name
azlin list
# Check spelling and resource group
azlin list --rg my-resource-group
Deletion Hangs¶
Symptoms: Command hangs during deletion
Solutions:
# Check Azure Portal for status
# VM may be in transitional state
# Wait a few minutes, then retry
azlin kill my-vm --force
# If still stuck, use Azure Portal to investigate
Permission Denied¶
Symptoms: "Insufficient permissions" error
Solutions:
# Verify you have Contributor or Owner role
# Check with Azure admin
# Try with explicit resource group
azlin kill my-vm --rg my-resource-group --force
Partial Deletion¶
Symptoms: VM deleted but some resources remain
Solutions:
# Check Azure Portal for orphaned resources
# Delete manually via Portal or CLI
# Common orphans:
az disk list --query "[?contains(name, 'my-vm')]"
az network nic list --query "[?contains(name, 'my-vm')]"
az network public-ip list --query "[?contains(name, 'my-vm')]"
Safety Best Practices¶
Always Verify Before Deleting¶
# Check what VM you're about to delete
azlin status my-vm
# Verify it's the right one
azlin connect my-vm # Quick check
Create Snapshots First¶
# Snapshot before deleting
azlin snapshot create my-vm
# Then delete
azlin kill my-vm --force
# Can restore later if needed
azlin snapshot list
azlin snapshot restore my-vm snapshot-name
Use Dry Run for Critical VMs¶
# Use azlin destroy for dry-run capability
azlin destroy my-vm --dry-run
# Review what would be deleted
# Then proceed with kill
azlin kill my-vm --force
Verify Subscription/Context¶
# Always check your context first
azlin context current
# Make sure you're in the right subscription
# Then delete
azlin kill my-vm --force
Comparison with Other Delete Commands¶
| Command | Purpose | Options |
|---|---|---|
azlin kill | Quick VM deletion | Basic, fast |
azlin destroy | VM deletion with options | Dry-run, delete-rg |
azlin killall | Delete all VMs in RG | Mass deletion |
azlin prune | Delete inactive VMs | Age/idle filters |
Common Workflows¶
Clean Up Test VMs¶
# Delete test VMs after work
azlin kill test-vm-1 --force
azlin kill test-vm-2 --force
azlin kill test-vm-3 --force
Remove Failed Provisioning¶
Pre-Recreation Cleanup¶
Automation Examples¶
Script to Delete Multiple VMs¶
#!/bin/bash
# Delete all VMs matching a pattern
VMS=$(azlin list --format json | jq -r '.[] | select(.name | contains("temp-")) | .name')
for vm in $VMS; do
echo "Deleting $vm..."
azlin kill "$vm" --force
done
echo "Cleanup complete"
Scheduled Cleanup¶
# Add to crontab for nightly cleanup
# Delete VMs tagged for deletion
# 0 2 * * * /path/to/cleanup-vms.sh
#!/bin/bash
VMS_TO_DELETE=$(azlin list --tag delete-after=$(date +%Y-%m-%d) --format json | jq -r '.[].name')
for vm in $VMS_TO_DELETE; do
azlin kill "$vm" --force
done
Related Commands¶
azlin destroy- Delete with dry-run and RG optionsazlin killall- Delete all VMs in resource groupazlin prune- Delete inactive VMs automaticallyazlin snapshot create- Backup before deletion
Source Code¶
- cli.py - Command definition
- vm_operations.py - Deletion logic