How-to bulk delete keys from Azure App Configuration

How-to bulk delete keys from Azure App Configuration

Have you ever had to bulk delete configs from Azure App Configurations? Azure Portal doesn't support this yet so here is how you'd do it!

If you’re already using Azure App Configuration in your Production application(s) then there is a good chance that you might have come across one of the following scenarios:

  • You accidentally imported either wrong set of configurations or configurations to a wrong label.
  • You are discontinuing a feature and would like to delete all configuration regarding it within or across all labels.

Recently, I came across both and thought that since Azure App Configuration’s portal UI still seems to be a work in progress, this is as good time as any to leverage Azure’s CLI SDK and write a script that would make configuration cleanup a piece of cake.

Here is my script (it is hosted on GitHub Gist).

Before we start looking into how-to run this, lets discuss a bit what it does and how it does it.

  1. It takes in 3 arguments: key, subscription, app config name. Key being the partial key you are wanting to delete. Subscription being the Azure Subscription which hosts the Azure App Configuration in which this key exists. App config name is simply the app configuration name in which the key to be deleted exists.
  2. Sets the given subscription as the active subscription in the CLI.
  3. Fetches all the keys from the provided Azure App Configuration & filters it in memory to identify the keys to delete & prints them to the console output.
  4. Waits for a final confirmation from the user that they are sure they want to delete the filtered keys.
  5. If user presses Enter, it deletes all keys one by one from the Azure App configuration.

Now that we know what the script does, lets have a look at how-to run it on your computer. I’m assuming you already have Azure CLI installed, if not, please go through the official docs here.

  1. Download the script shared above, into the downloads folder.
  2. Open PowerShell and type in the following to change your working directory to downloads.
cd C:\\Users\\{YOUR\_USER\_HERE}\\Downloads

3. Now, to log into Azure using the Azure CLI, run the following:

az login

4. In the new window that pops open, enter your Azure credentials to login or pick an already signed in account.

5. Lastly, run the script using the following command to see a list of keys that will be deleted.

.\\HA-DeleteKeysFromAzAppConfig.ps1 -key '{YOUR\_PARTIAL\_KEY}' -subscription '{YOUR\_SUBSCRIPTION\_NAME/ID}' -appConfigName '{YOUR\_APP\_CONFIG}'

6. If you’re ready to delete, press enter and sit back while the script does the work for you 😁