#!/bin/bash

echo "Finding unattached Public IPs..."

# List IPs where ipConfiguration is null
UNUSED_IPS=$(az network public-ip list --query "[?ipConfiguration==null].id" -o tsv)

if [ -z "$UNUSED_IPS" ]; then
    echo "No unattached Public IPs found."
    exit 0
fi

for IP_ID in $UNUSED_IPS; do
    echo "Deleting Public IP: $IP_ID"
    az network public-ip delete --ids "$IP_ID"
done

echo "Cleanup complete."
