When you delete a virtual machine (VM) in Azure, by default, any disks that are attached to the VM aren't deleted. This helps to prevent data loss due to the unintentional deletion of VMs. However, as a fortunate side effect, you will continue to pay for unattached disks.
Oh? You don't want to pay for disks you'll never use again? This workflow is for you.
This workflow will first look for all Azure disks in a Subscription (or optionally, resource group). Then, it will filter that list for the disks that aren't attached to a Virtual Machine. Next, it will wait for your approval. Finally, once approval has been granted, it will delete the unused disks. Nice work!
Before you run this workflow, you will need the following:
- An Azure Subscription
- An Azure Service Principal with permissions to manage compute resources
- One or more running Azure Disks that are unattached.
Follow these steps to configure the workflow. Doing this will enable Relay to connect to your Azure account.
You may see a warning that you are missing a required connection. This means you will need to add your Azure credentials as a Connection.
- Click Fill in missing connections or click Settings in the side nav.
- Find the Connection named
my-azure-account
and click the plus sign (+).
-
Fill out the form:
- Name - You can’t change this with the form. The name is supplied by the YAML. If you wanted to change it you would need to do so in the Code tab.
- Subscription ID - Enter your Azure Subscription ID
- Client ID - Enter your Azure Client ID associated with the service principal
- Tenant ID - Enter your Azure Tenant ID associated with the service principal
- Secret - Enter your Azure Secret associated with the service principal
-
Click Save
Follow these steps to run this workflow.
-
Click Run workflow and wait for the workflow run page to appear.
-
Supply values for the parameters fields when the modal appears:
- dryRun -
true
orfalse
true
if you dont want to actually delete the resources. Use this to test the workflow and ensure it is behaving as expected.false
if you want the resources to be immediately deleted.
- dryRun -
WARNING! Be careful setting
dryRun
tofalse
. Though the workflow comes with an approval step, once approved the resources will be terminated. Please use caution.
Follow these steps to run this workflow on a schedule:
- Un-comment out the included Trigger block in the workflow YAML. You can do this in the Code tab.
TIP: If you're using the Relay code editor, highlight the
triggers
section and type⌘ + /
(Mac) orCtrl + /
(Windows) to uncomment.
# triggers:
# - name: schedule
# source:
# type: schedule
# schedule: '0 * * * *'
# binding:
# parameters:
# dryRun: true
- Configure the
schedule
trigger:- Supply the run interval in cron format.
- Configure the following parameter bindings:
- Specify whether
dryRun
should be set totrue
orfalse
.
- Specify whether
binding:
parameters:
dryRun: true
- Click Save changes