使用 ARM 检索存储帐户连接字符串

The*_*der 7 azure-resource-manager

我是编写 Azure 资源管理器模板的新手;我需要检索 Azure 存储帐户连接字符串。我可以使用[listKeys(variables('storageAccountId'), '2019-04-01').keys[0].value]where storageAccountIdis检索它的访问密钥,[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]但我无法为连接字符串(主要)这样做。

现在,我的问题是我们有listKeys检索访问密钥的功能,我们是否也有一些系统功能来检索连接字符串?还是我们需要连接并创建连接字符串?我有存储帐户名称和资源组名称的值。我如何使用 ARM 做到这一点?

Jim*_* Xu 9

根据我的研究,Azure ARM 模板没有提供我们可以用来列出存储帐户连接字符串的功能。我们可以通过 ARM 模板函数来列出 access key( listkeys) 列出账户 SAS token( listAccountSas) 或列出服务 SAS token( listServiceSas)。更多详细信息,请参阅文档

所以如果你想获取存储帐户连接字符串,我建议你使用 Azure ARM 模板函数concat来组合连接字符串。例如

"outputs": {  
        "storageAccountConnectionString": {  
            "type": "string",  
            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId(parameters('resourceGroupName'),'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-04-01').keys[0].value,';EndpointSuffix=core.windows.net')]"  
        },

        }  
    }  
Run Code Online (Sandbox Code Playgroud)