Recently I needed a way to modify application settings for several Azure Function Apps that I had deployed using Azure Devops.
Application settings for Azure Web apps and Azure Function apps can be created and managed using Azure CLI.
I have created a simple script that can be incorporated into an Azure DevOps Pipeline to allow modification of app settings during Azure DevOps Pipeline release of function apps.
# Define Resource Group
$resourceGroup = "sanj-rg"
# Define Function App
$functionApp = "sanj-func"
$AppSettingsHash = @{
# Add app settings here
USER = "USERNAME1";
PASSWORD1 = "@Microsoft.KeyVault(SecretUri=https://kv-sanj-app.vault.azure.net/secrets/password1/)";
SANJ_APP_REQUEST_FLOW_URL = "https://prod-01.uksouth.logic.azure.com:443/workflows//triggers/manual/paths/invoke?api-version=2021-01-01";
SANJ_PAYMENT_REQUEST_AUTH_CODE = "@Microsoft.KeyVault(SecretUri=https://kv-sanj-app-uat.vault.azure.net/secrets/payment-request-auth-code/)";
SANJ_PAYMENT_REQUEST_FLOW_URL = "https://prod-50.westeurope.logic.azure.com/workflows/1233211c0000000d00aff99999c/trizzzzzzzzzzz"
}
ForEach ($AppSettingAdd in $AppSettingsHash.GetEnumerator())
{
az functionapp config appsettings delete --name $functionApp --resource-group $resourceGroup --setting-names $($AppSettingAdd.Name)
az functionapp config appsettings set --name $functionApp --resource-group $resourceGroup --settings "$($AppSettingAdd.Name) = $($AppSettingAdd.Value)"
}
Line 2 defines the resource group
Line 4 defines the function app
A PowerShell Hashtable contains a name-value pair array for the application settings to apply to the function app. Some values reference secrets stored within Key Vault or to URLs.
A foreach loop is used to apply the app setting values from the PowerShell Hashtable. An az functionapp config appsettings delete command followed by az functionapp config appsettings set command allows modification of existing app setting values.
This PowerShell script containing Azure CLI commands can be used in a CI/CD pipeline with an Azure CLI task. Developers are able to modify the app setting section of the script with values as required so that the modifications can be automatically deployed by the Azure Pipeline.
