← Back to Engineering Blog
πŸ—“οΈ Oct 10, 2023 ⏱️ 2 min read

Automating Cloud Hygiene: Reclaiming Unattached Managed Disks & Public IPs at Scale

How automated Azure CLI and Azure Automation Runbooks deleted orphaned Premium SSD disks and unattached Public IPs, saving $15,000 monthly.

πŸŽ™οΈ Listen to Article READY
AI Audio Synthesis Narrator
Share Post:

β€œDeleting an Azure Virtual Machine does not automatically delete its associated Premium SSD managed disk or static Public IP. Unattached resources accumulate silently on your monthly bill.”

While conducting a Cloud FinOps audit for a banking client at Kyndryl, we discovered over 400 unattached 1TB Premium SSD managed disks (DiskState = Unattached) left behind by decommissioned Kubernetes nodes.


Architecture: Automated Azure Resource Reclamation

We built an Azure Automation Runbook running PowerShell and Azure CLI scripts on a weekly cron schedule.

  • Orphaned Managed Disk Sweep: Identifies managed disks in Unattached state for over 14 days and flags them for deletion.
  • Unattached Public IP Cleanup: Identifies static public IP addresses not bound to any Network Interface Card (NIC) or Load Balancer.

[!CAUTION] Always take a final disk snapshot and tag orphaned disks with PendingDeletion = True for 7 days before executing permanent hard deletion scripts.

# # Azure CLI Automation Script to Reclaim Unattached Managed Disks
az disk list --query "[?managedBy==null && diskState=='Unattached'].{Name:name, ResourceGroup:resourceGroup, SizeGB:diskSizeGb}" -o table

# Delete unattached disks after snapshotting
az disk delete --ids $(az disk list --query "[?managedBy==null && diskState=='Unattached'].id" -o tsv) --yes

The Verdict

Key Takeaway

Deploy Automated Scheduled Cleanup Runbooks for Orphaned Cloud Assets.

Automating Azure unattached disk and IP reclamation eliminates cloud waste, reducing monthly subscription invoices by 15% to 30%.

SKS

Sachin Kumar Sharma

Associate Director (Infrastructure & Cloud Architecture Strategy) | 20+ Yrs Exp

Architecting resilient multi-cloud enterprise landing zones, SDN overlay fabrics, DevSecFinOps automation pipelines, and autonomous Agentic AI platforms.