【发布时间】:2019-04-06 15:22:17
【问题描述】:
我在我们的项目中使用了几个 ARM 模板,每个模板都用于不同的组件,还有一个 Common ARM 模板,其中包含大多数元素需要工作的所有资源,如 SqlServer、存储帐户、Redis缓存(所有元素仅此资源之一)
问题是,由于存储帐户位于单独的 ARM 模板(通用基础架构 ARM 模板)中,我无法从组件模板访问存储帐户密钥。我需要这个来正确设置连接字符串的值,以便组件使用它。如果我在组件模板中包含存储帐户资源,我可以通过以下方式访问它:
[concat('DefaultEndpointsProtocol=https;AccountName=',
variables('YFO.StorageAccount.Name'), ';AccountKey=',
listKeys(resourceId('Microsoft.Storage/storageAccounts',
variables('YFO.StorageAccount.Name')), providers('Microsoft.Storage',
'storageAccounts').apiVersions[0]).keys[0].value)]
但是当我从组件模板中删除它时,应该是这样,然后我收到以下错误:
New-AzureRmResourceGroupDeployment:
错误:代码=无效模板;消息=部署模板验证失败:'模板引用 '**********' 无效:不能 查找具有此名称的模板资源或资源副本。请参见 https://aka.ms/arm-template-expressions/#reference 了解使用详情。'
如果资源在您尝试部署的模板之外,listKeys 似乎无法完成工作
对于 AppInsights 组件,我能够做到这一点:
[reference(concat('Microsoft.Insights/components/',
variables('AppInsightsName'))).InstrumentationKey]
即使 AppInsights 资源位于组件 ARM 模板之外,但我无法使用存储帐户执行此操作,因为在引用函数中为存储帐户返回的对象如下:
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"supportsHttpsTrafficOnly": false,
"encryption": {
"services": {
"file": {
"enabled": true,
"lastEnabledTime": "2018-08-18T06:05:57.3069884Z"
},
"blob": {
"enabled": true,
"lastEnabledTime": "2018-08-18T06:05:57.3069884Z"
}
},
"keySource": "Microsoft.Storage"
},
"provisioningState": "Succeeded",
"creationTime": "2018-08-18T06:05:56.8228127Z",
"primaryEndpoints": {
"blob": "https://yfomormonttest.blob.core.windows.net/",
"queue": "https://yfomormonttest.queue.core.windows.net/",
"table": "https://yfomormonttest.table.core.windows.net/",
"file": "https://yfomormonttest.file.core.windows.net/"
},
"primaryLocation": "westeurope",
"statusOfPrimary": "available",
"secondaryLocation": "northeurope",
"statusOfSecondary": "available"
}
有什么线索吗?
感谢和问候。
【问题讨论】:
标签: arm azure-storage