In this tutorial, you will find Azure resources that are likely safe to delete. This can be a significant cost savings: one CloudQuery customer saves approximately $30k/month in costs by using queries like this. Beyond cost, some of these resources are a compliance and security risk if they remain as-is.
Get started
Install CloudQuery, point it at PostgreSQL (local Docker or Azure PG), and use a read-only role (e.g., Reader at the subscription). Save the config as azure-safe-deletes.yaml, export POSTGRES_URL, ensure your Azure credentials are set (CLI login/service principal), and then run a single CloudQuery sync. The SQL below gives a screenshot-ready “top wins” list.
CloudQuery config and sync
kind: source spec: name: azure path: cloudquery/source/azure version: 'vX.Y.Z' # pin a recent version tables: - azure_compute_disks - azure_compute_virtual_machines - azure_network_public_ip_addresses - azure_network_interfaces # (Optional) Fetch VM runtime status for better power-state signals: # table_options: # azure_compute_virtual_machines: # VirtualMachinesOptions: # - StatusOnly: "true" # or Expand: "instanceView" if supported by your setup destinations: [postgres]
-- Disks with no VM attachment (managed_by is NULL or empty). -- If present, we also surface size via properties->>'diskSizeGB'. SELECT d.subscription_id, d.location, d.name, d.id, COALESCE(NULLIF(d.managed_by, ''), '—') AS managed_by, NULLIF(d.properties->>'diskState', '') AS disk_state, (d.properties->>'diskSizeGB')::int AS disk_size_gb, d.tags FROM azure_compute_disks d WHERE COALESCE(NULLIF(d.managed_by, ''), '') = '' ORDER BY disk_size_gb DESC NULLS LAST, d.location, d.name;
Unassociated Public IPs --> you pay when idle
Unattached public IPs are billable (especially static)
-- Public IPs without an ipConfiguration (not associated to a NIC/LB). -- Azure writes the association under properties.ipConfiguration. SELECT p.subscription_id, p.location, p.name, p.id, (p.properties->>'ipAddress') AS current_ip, p.properties->>'publicIPAllocationMethod' AS allocation_method, p.properties->>'ipVersion' AS ip_version, p.sku, p.tags FROM azure_network_public_ip_addresses p WHERE (p.properties ? 'ipConfiguration') IS FALSE OR p.properties->'ipConfiguration' IS NULL ORDER BY p.location, p.name;
Stopped/Deallocated VMs
-- VMs whose power state looks 'stopped' or 'deallocated' (when instance_view is available). -- This relies on runtime status being fetched (see optional table_options in YAML). WITH power AS ( SELECT vm.subscription_id, vm.location, vm.name, vm.id, -- Look inside instance_view.statuses[*].code for "PowerState/..." ( SELECT s->>'code' FROM jsonb_path_query(vm.instance_view, '$.statuses[*] ? (@.code like_regex "PowerState/.*")') AS s LIMIT 1 ) AS power_code, vm.tags FROM azure_compute_virtual_machines vm ) SELECT subscription_id, location, name, id, power_code, tags FROM power WHERE power_code ~* 'PowerState/(stopped|deallocated)' ORDER BY location, name;
Wrap-up
CloudQuery is lightning-fast data movement that runs on your infrastructure. This is perfect for working with sensitive data (like your key Azure resources!). Schedule a demo to see how CloudQuery can help you realize these cost savings.
Written by
Chris Reuter
VP of Marketing at CloudQuery. I like Maine (the US State), software & analytics, woodworking, hiking, travel, and spending time with my wife & dog.
Try CloudQuery yourself
Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.
Download →
Schedule a demo →
Related posts
AWS
Azure
GCP
Security
Tutorials
How to Find Internet-Facing Cloud Assets in AWS, Azure and GCP
Find all internet-facing cloud resources across AWS, Azure, and GCP. Identify exposed VMs, storage, databases, and load balancers to reduce attack surface.
Adam Cobb
November 5, 2025
Azure
Security
Tutorials
How to Find Azure Resources Affected by TLS 1.0/1.1 Deprecation
Identify Azure resources impacted by TLS 1.0 and 1.1 deprecation using CloudQuery. Audit your cloud assets and ensure TLS compliance using SQL queries.
Ben Bernays
January 29, 2025
Azure
Cloud Asset Inventory
Tutorials
How to build a Cloud Asset Inventory for Azure
Learn how to build an Azure cloud asset inventory with CloudQuery and PostgreSQL. Covers setup, dbt transformations, and visualizing assets for security and compliance.
Joe Karlsson
November 25, 2024
AWS
Azure
Cloud Asset Inventory
GCP
Tutorials
How to Build a Multi-Cloud Asset Inventory
Build a multi-cloud asset inventory across AWS, GCP, and Azure with this step-by-step guide covering data collection, transformation, and storage.
Joe Karlsson
August 29, 2024
Azure
Security
Tutorials
Enhance your Cloud Asset Inventory Using Wiz + Azure
Enhance your Azure cloud asset inventory with CloudQuery’s Wiz plugin. Gain immediate insights into vulnerabilities and misconfigurations.
Kevin Rheinheimer
July 2, 2024
Azure
Cloud Asset Inventory
Tutorials
Inventory Microsoft Azure with CloudQuery
Sync your Microsoft Azure infrastructure with CloudQuery. Build a complete Azure asset inventory for security, compliance, and cost analysis using SQL.
Gisela Torres
November 30, 2021
AWS
Azure
GCP
Security
How Do You Run CloudQuery Without Static Credentials?
Workload identity federation for GCP and Azure, RDS IAM auth, and Lakebase OAuth let self-hosted CloudQuery syncs run without stored static credentials.
Ben Bernays
September 28, 2026
Tutorials
How to Automatically Update CloudQuery Integrations with Renovate
Configure Renovate to automatically update CloudQuery integration versions in your YAML files using the CloudQuery Hub API as a custom datasource.
Matthew M
May 20, 2026
AWS
Security
Tutorials
Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond
Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.