DEV Community

Paul Yu
Paul Yu

Posted on • Originally published at paulyu.dev on

Purging Deleted Azure Key Vaults

Do you constantly provision and delete Azure Key Vaults?

If so, you may have noticed attempts to recreate a recently deleted key vault will result in the following error:

The vault name is already in use.
Enter fullscreen mode Exit fullscreen mode

This is because Azure Key Vaults are kept in a deleted state and not automatically purged. You must manually purge these key vaults to be able to reuse the name.

To confirm the key vault in question is in "deleted" state, you can run the following:

az keyvault list-deleted --query "[].name" -o tsv
Enter fullscreen mode Exit fullscreen mode

Using Bash, we can loop through all deleted key vaults and purge them so that the name can be re-used:

az keyvault list-deleted --query "[].name" -o tsv | while read keyvault; do
  az keyvault purge -n $keyvault;
done
Enter fullscreen mode Exit fullscreen mode

Top comments (0)