Find unattached Azure managed disks
This tutorial walks you through building a read-only flow that finds unattached Azure managed disks and emails a report. Along the way, you'll learn how to combine an Azure node with Filter and Notification nodes.
Goal and objectives
-
Goal: Create a flow that lists Azure managed disks in a subscription, keeps disks whose
properties.diskStateisUnattached, and emails their details. The flow never modifies or deletes a disk. -
Objectives: In this tutorial, you'll learn how to:
-
Run the Azure
Disks_Listaction from CloudFlow. -
Filter a list of Azure resources by a nested field.
-
Format the results as an email table and skip the notification when no disks match.
-
Test the nodes and inspect a completed run.
-
Understand Azure disk states
Azure reports an unattached managed disk with diskState set to Unattached. A disk in the Reserved state remains attached to a stopped and deallocated virtual machine, so this flow intentionally excludes it. For the complete list of states, see Disk State in the Azure REST API reference.
An unattached disk can still contain data that your organization needs. This tutorial only reports candidates. Before deleting a disk, verify its owner, retention requirements, resource locks, and recovery plan, and create a snapshot if you might need the data later. Disk deletion is permanent; see Find and delete unattached Azure managed and unmanaged disks.
Before you begin
-
Make sure your DoiT account has the CloudFlow Editor or CloudFlow Manager permission. See CloudFlow permissions.
-
Connect the Azure tenant that contains the subscription you want to inspect. The connected permissions must include
Microsoft.Compute/disks/read; the Azure Reader role includes this permission. -
Create an Azure CloudFlow connection. Creating the connection requires the CloudFlow Manager permission.
-
Find the Azure subscription ID that you want the flow to inspect.
Start building
-
Sign in to the DoiT console, select Automation and operations from the top navigation mega menu, and then select CloudFlow.
-
Select Create CloudFlow.
Step 1: Add a trigger
In the What should start your flow block, select Manually start. A manual trigger makes it easier to validate the results while you build the flow. You can switch to a custom schedule after validation.
Step 2: List managed disks
-
In the What do you want to do block, select Perform an action, choose Azure, search for
Disks_List, and then select the matching action. -
Name the node
listManagedDisks. -
On the Parameters tab, enter the Subscription ID. This action lists disks across the subscription, so it does not require a resource group.
-
On the Connection tab, select the Azure connection that uses the subscription's tenant permissions.
-
On the Test tab, select Test. Confirm that the response contains a
valuelist and that its disk entries includename,id, andproperties.diskState. -
Select Save as test data so the output is available when you test the filter.
Azure actions automatically follow paginated responses for supported operations. See Test nodes.
Step 3: Filter unattached disks
-
Add a Filter node and name it
filterUnattachedDisks. -
In Field, select the plus icon (+) and choose
2. listManagedDisks.value. -
In Filter 1, set the condition
properties.diskState == Unattached. -
Test the node. Confirm that every result has
properties.diskStateset toUnattached.
The filter excludes attached disks and disks reserved by stopped and deallocated virtual machines.
Step 4: Email the report
-
Add a Send a message node and name it
notifyUnattachedDisks. -
Set Notification provider to Email, enter the recipient address, and set the subject to
Unattached Azure managed disks. -
In Message, enter an introduction, then add a
<table>block. Use the plus icon (+) to insert each referenced field from3. filterUnattachedDisks:The following Azure managed disks are unattached:<table>Disk name: {3. filterUnattachedDisks.name}Resource ID: {3. filterUnattachedDisks.id}Location: {3. filterUnattachedDisks.location}Size (GiB): {3. filterUnattachedDisks.properties.diskSizeGB}</table> -
Select Don't send notification if no results so CloudFlow skips the email when the filter matches no disks.
-
Test the notification and review the rendered table.
Publish and run the flow
Select Publish, then select Run. On the Run history page, expand each node to inspect its input and output.
When the run finds unattached disks, the recipient receives a table with one row per disk. When no disk matches, the flow completes without sending an email.
Optional: Schedule the report
After you validate the flow, replace the manual trigger with a custom schedule, such as a weekly schedule. Keep the notification setting that skips empty results to avoid sending unnecessary reports.