I am trying to determine a way to delete unattached disks if they have been unattached for a specific period of time:
Pseudo code
if state = "unattached" & date_unattached > 7 days then DELETE
I currently have the following:
compute_client = ComputeManagementClient(credentials, subscription_id)
for disk in compute_client.disks.list():
print(disk.as_dict())
However, the payload only gives me a date/time for when the disk was created.
I tried attaching the disk to a VM but the activity logs didn't seem to update (will keep monitoring). I was hoping the disk logs might give this information.
Is there a simple way to find when this disk became unattached?
I am also thinking maybe using a DB to track when the disk was first discovered and then count the number of days between the first time the script ran and the next if the disk state is still the same and get the difference. I would need to run it daily as a user may attach/detach regularly (edge case)