【问题标题】:Retrieve Storage Account Connection String using ARM使用 ARM 检索存储帐户连接字符串
【发布时间】:2020-03-21 11:52:02
【问题描述】:

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

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

【问题讨论】:

    标签: azure-resource-manager


    【解决方案1】:

    根据我的研究,Azure ARM 模板没有提供我们可以用来列出存储帐户连接字符串的功能。我们只需要 ARM 模板函数来列出访问密钥(listkeys)列出帐户 SAS 令牌(listAccountSas)或列出服务 SAS 令牌(listServiceSas)。更多详情请参考document

    所以如果你想获取存储账户连接字符串,我建议你使用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')]"  
            },
    
            }  
        }  
    

    【讨论】:

    • 但是如果我们使用 ARM TTK 进行市场部署验证,它会抱怨硬编码 core.windows.net,即使我们使用内部 concat() 断开字符串,在部署时我仍然会遇到奇怪的错误,例如 - expected token 'Identifier' and actual 'LeftSquareBracket'.'. 即使所有 ARM TTK 测试都通过了。
    猜你喜欢
    • 1970-01-01
    • 2018-12-20
    • 2015-12-02
    • 1970-01-01
    • 2021-05-31
    • 2021-04-11
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    相关资源
    最近更新 更多