Arr matey! This here document be explainin' the azlin destroy command fer cleanly deletin' VMs and all their associated resources.
The destroy command completely removes a VM and ALL associated Azure resources, including:
- Virtual Machine itself
- Network Interfaces (NICs)
- Network Security Groups (NSGs) [NEW]
- OS and data disks
- Public IP addresses (if attached)
This ensures no orphaned resources remain after deletion, allowing ye to reuse VM names without conflicts.
# Delete a VM with all resources
azlin destroy my-vm-name
# Show what would be deleted (dry-run)
azlin destroy my-vm-name --dry-run
# Skip confirmation prompt
azlin destroy my-vm-name --forcevm_name- Name of the VM to destroy (or session name)
| Flag | Description |
|---|---|
--resource-group, --rg |
Specify resource group (uses config default if not provided) |
--config |
Path to custom config file |
--force |
Skip confirmation prompt |
--dry-run |
Show what would be deleted without actually deleting |
--delete-rg |
Delete the entire resource group (DANGEROUS) |
Resources are deleted in the followin' order to handle dependencies:
- Virtual Machine - The VM instance itself
- Network Interfaces (NICs) - All network interfaces attached to the VM
- Network Security Groups (NSGs) - NSGs discovered from each NIC [NEW]
- OS and Data Disks - All disks attached to the VM
- Public IP Addresses - Public IPs associated with NICs (if any)
- NSGs be discovered by querying each NIC attached to the VM
- NSG deletion be best-effort (graceful if NSG doesn't exist or already deleted)
- Multiple NICs may share the same NSG (only deleted once)
- No errors if NSG not found (handles race conditions)
azlin destroy azlin-vm-20250112-120000Output:
VM Details:
Name: azlin-vm-20250112-120000
Resource Group: my-dev-rg
Status: Running
IP: 20.123.45.67
Size: Standard_D2s_v3
This will delete the VM and all associated resources (NICs, NSGs, disks, IPs).
This action cannot be undone.
Are you sure you want to delete this VM? [y/N]: y
Deleting VM: azlin-vm-20250112-120000
✓ Deleted VM
✓ Deleted NIC: azlin-vm-nic
✓ Deleted NSG: azlin-vm-nsg
✓ Deleted disk: azlin-vm-osdisk
✓ Deleted Public IP: azlin-vm-ip
Successfully deleted azlin-vm-20250112-120000 and all associated resources.
azlin destroy my-dev-vm --dry-runOutput:
DRY RUN: The following resources would be deleted:
VM: my-dev-vm
├── Network Interfaces:
│ ├── my-dev-vm-nic-1
│ └── my-dev-vm-nic-2
├── Network Security Groups:
│ └── my-dev-vm-nsg
├── Disks:
│ ├── my-dev-vm-osdisk
│ └── my-dev-vm-datadisk-0
└── Public IPs:
└── my-dev-vm-ip
Total: 1 VM, 2 NICs, 1 NSG, 2 disks, 1 Public IP
No resources were deleted (--dry-run mode).
azlin destroy test-vm-001 --forceUse Case: Automated scripts or CI/CD pipelines where manual confirmation not be needed.
# Delete VM in specific resource group
azlin destroy vm-name --rg production-rg
# Delete VM in development group
azlin destroy vm-name --rg dev-rgAfter successful deletion, ye'll see:
Successfully deleted <vm-name> and all associated resources.
Resources deleted:
- VM: <vm-name>
- NIC(s): <nic-count> deleted
- NSG(s): <nsg-count> deleted
- Disk(s): <disk-count> deleted
- Public IP(s): <ip-count> deleted
azlin destroy nonexistent-vmOutput:
Error: VM 'nonexistent-vm' not found in resource group 'my-rg'.
Error: Insufficient permissions to delete VM.
Ensure you have 'Contributor' or 'Owner' role on the resource group.
If some resources fail to delete, ye'll see:
Warning: Some resources could not be deleted:
✓ Deleted VM: my-vm
✓ Deleted NIC: my-vm-nic
✗ Failed to delete NSG: my-vm-nsg (ResourceInUse)
✓ Deleted disk: my-vm-osdisk
VM deleted but some resources remain. Manual cleanup may be required.
After destroy completes successfully, the VM name be immediately available for reuse:
# Delete old VM
azlin destroy my-project-vm --force
# Create new VM with same name
azlin new --name my-project-vmPreviously, orphaned NSGs would prevent name reuse. This be fixed with NSG cleanup.
If multiple VMs share a Network Security Group:
- NSG only deleted when the LAST VM using it be destroyed
- Azure prevents deletion of NSGs still attached to other resources
- This be safe and automatic - no user action needed
azlin destroy my-vm --delete-rg --forceWARNING: This deletes the ENTIRE resource group, not just the VM. All resources in the group be permanently lost.
| Command | Purpose | Confirmation |
|---|---|---|
azlin destroy <vm-name> |
Delete single VM | Per-VM prompt |
azlin killall |
Delete all VMs in RG | Single bulk prompt |
azlin destroy --delete-rg |
Delete entire RG | Extra warning |
azlin list- List VMs before deletionazlin killall- Bulk deletionazlin status <vm>- Check VM details before destroying
Problem: NSG or NIC cannot be deleted because it be attached elsewhere.
Solution: Azure prevents deletion automatically. The VM deletion succeeds, orphaned resources be cleaned up when no longer in use.
Problem: Deletion takes longer than 5 minutes.
Solution:
# Use --no-wait flag (advanced)
export AZLIN_NO_WAIT=1
azlin destroy my-vm --forceProblem: VM name doesn't match what ye expect.
Solution:
# List all VMs first
azlin list
# Use exact name from list output
azlin destroy azlin-20250112-143022- Quick Reference Guide - All azlin commands
- VM Lifecycle - Lifecycle management
- Resource Management - Architecture overview