获取 ARM 模板中应用配置的只读连接字符串

问题描述

您好,我想在 ARM 模板中添加应用程序配置只读连接字符串

"appSettingsShared": {
            "value": [
              {
                "name": "RedisCache:ConnectionString","value": "[concat(variables('RedisCacheName'),'.redis.cache.windows.net:6380,abortConnect=false,ssl=true,password=',listKeys(resourceId('Microsoft.Cache/Redis',variables('RedisCacheName')),'2015-08-01').primaryKey)]"
              },{
                "name": "AppConfig:ConnectionString","value": "???"
              }
            ]

我知道如何使用 Azure CLI 做到这一点:

az appconfig credential list -g $resourceGroup   -n $appConfigName --query "([?name=='Primary Read Only'].connectionString)[0]" --output tsv

非常感谢任何帮助。

解决方法

您可以使用 listkeys 模板函数来检索您的 configStore 键和连接字符串。实现类似于 Configuration Stores - List Keys API,它返回类似于以下内容的响应:

"value": "[listKeys(resourceId('Microsoft.AppConfiguration/configurationStores',variables('configurationStore_name')),'2019-11-01-preview').value[2].connectionString]"

由于您想访问只读连接字符串,您可以在您的 ARM 模板中访问它,如下所示:

value[3].connectionString

这将为您提供主要只读连接字符串。同样,######get actuall installed software Function Get-Package { $SofNames = Get-Package -ProviderName programs -IncludeWindowsInstaller | Select- Object -ExpandProperty Name | sort-object for($i=0; $i -lt $SofNames.count;$i++){ "$($i): $($SofNames[$i])"} } #####fetch software on remote machine $pcname = read-host "Gebe den PC Namen/IP Adresse ein" Invoke-Command -ComputerName $pcname ` -ScriptBlock ${Function:Get-Package} #####uninstall software on remote machine $iN = Read-Host -Prompt "Enter Number" function Uninstall-Package {get-Package -Name $iN | Uninstall-Package} Invoke-Command -ComputerName $pcname ` -ScriptBlock ${Function:uninstall-Package} 将检索Secondary Read Only 连接字符串。