Skip to main content

VM Public IP Cleanup

Synopsis​

Intended end result: Safely detach and delete VM public IP resources when exposure is no longer required.

How this page gets you there: Resolve the exact NIC/IP config attachment first, then detach and remove the public IP without orphaning dependencies.

Use this only when you intentionally want to detach and remove the VM public IP.

RG="ai4gl-condor-uat-rg"
VM_PIP="ai4gl-condor-uat-pip-vm"

PIP_ID=$(az network public-ip show -g "$RG" -n "$VM_PIP" --query id -o tsv)
read NIC_NAME IPCFG_NAME <<< "$(az network nic list -g "$RG" --query "[?ipConfigurations[?publicIPAddress.id=='$PIP_ID']].[name, ipConfigurations[?publicIPAddress.id=='$PIP_ID']|[0].name] | [0]" -o tsv)"

az network nic ip-config update -g "$RG" --nic-name "$NIC_NAME" -n "$IPCFG_NAME" --remove publicIpAddress
az network public-ip delete -g "$RG" -n "$VM_PIP"