az functionapp config is truncating trailing bracket

43 Views Asked by At

I have the following in my PowerShell script:

foreach ($row in $csv) {
    # split the key into Key Vault name and secret name
    $keyParts = $row.key -split '\|'
    $functionAppName = $keyParts[0]
    $settingName = $keyParts[1]
    $value = $row.value
    
    if ($value -match '^https://.*\.vault\.azure\.net/secrets/.*') {
        $value = "@Microsoft.KeyVault(SecretUri=$value)"
    }
    write-host "Setting $settingName for $functionAppName to $value"
    az functionapp config appsettings set --resource-group $rg --name $functionAppName --settings "$settingName=$value"

}

The write-host output looks good:

Setting mysetting for myapp to @Microsoft.KeyVault(SecretUri=https://mykv.vault.azure.net/secrets/ServiceBusConnectionString/)

However, when I use the Azure Portal to inspect the value that been inserted I can see that the trailing closing bracket has been truncated - so I have

@Microsoft.KeyVault(SecretUri=https://mykv.vault.azure.net/secrets/ServiceBusConnectionString/

2

There are 2 best solutions below

2
RithwikBojja On

The below script worked for me, try to integrate into your script:

$rithvalue = "https://rithtest.vault.azure.net/secrets/ServiceBusConnectionString/"
if ($rithvalue -match '^https://.*\.vault\.azure\.net/secrets/.*') {
    $rithvalue = "@Microsoft.KeyVault(SecretUri=$rithvalue)"
}
$rithsetting="testsetting"
az functionapp config appsettings set --name "rithwik76" --resource-group "testrg" --settings "$rithsetting=$rithvalue"

enter image description here

Output:

enter image description here

enter image description here

0
Rob Bowman On

The cause of this problem was due to a bug in az cli as described at: https://github.com/Azure/azure-cli/issues/10066

I am running azure-cli 2.53.1

As a work-around, I updated the line

az functionapp config appsettings set --resource-group $rg --name $functionAppName --settings "$settingName=$value"

to:

cmd /c "az functionapp config appsettings set --name $functionAppName --resource-group $rg --settings `"$settingName=$value`""