通过 Azure cli 创建应用服务应用设置时字符串中的右括号丢失

Closing parentheses in string dropped when creating app service app setting via Azure cli

我正在通过 Azure cli 在 Azure 应用服务中创建应用程序设置。设置的值是一个 KeyVault 引用,如果您不熟悉它,它有一个特殊的语法:

@Microsoft.KeyVault(SecretUri=https://something.vault.azure.net/secrets/SomeKey/xxxxxxxxxx)

我的 powershell 脚本创建了 KeyVault 机密并存储了机密 ID。然后我构建应用程序设置值,如:

$new_secret_id = "@Microsoft.KeyVault(SecretUri=$secret_id)"

我使用 Write-Host 来验证 $new_secret_id 在这一点上是完全正确的。

然后我使用以下命令创建应用程序设置,但始终缺少尾随的括号,这导致应用程序设置成为逐字值而不是 KeyVault 引用。如果我硬编码一个值而不是使用它工作的变量 $secret_id,它不会去除结束 ).

az webapp config appsettings set `
    --resource-group $rg `
    --name $app_name `
    --settings A_SECRET=$new_secret_id

Update

我一直在尝试 $secred_id 的各种值组合。它似乎只在值为 URL.

时发生

这已经是一个记录在案的问题(功能):

https://github.com/Azure/azure-cli/issues/8506

We made this change to help prevent the shell from interpreting the special characters in the setting value

如 github 评论中所述,您可以嵌入双引号。

--settings "A_SECRET=""@Microsoft.KeyVault(SecretUri=$secret_id)"""