azure - Azure RM 链接模板之间的依赖关系
问题描述
我计划在我的资源组中创建两个资源:一个 Web 应用程序和一个服务总线。Web 应用程序将有一个连接字符串指向服务总线。因此,我需要先创建服务总线,然后添加带有连接字符串的 Web 应用程序。对于 Web 应用程序和服务总线,我都使用链接模板。我的简化azuredeploy.json
看起来像这样:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "myWebAppDeploy",
"apiVersion": "2017-05-10",
"type": "Microsoft.Resources/deployments",
"dependsOn": [
"UNKNOWN-DEPENDENCY"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "link/to/webapp.azuredeploy.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"name": {
"value": "myWebApp"
},
"connectionStrings": {
"value": {
"serviceBusConnectionString": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', 'myServiceBus', 'RootManageSharedAccessKey'), '2017-04-01').primaryConnectionString]"
}
}
}
}
},
{
"name": "myServiceBusDeploy",
"apiVersion": "2017-05-10",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "link/to/servicebus.azuredeploy.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"name": {
"value": "myServiceBus"
}
}
}
}
]
}
无论我在UNKNOWN-DEPENDENCY
部分中输入什么内容,都会收到以下错误:
Template deployment returned the following errors:10:02:23 AM - Resource Microsoft.ServiceBus/namespaces/authorizationRules 'myServiceBus/RootManageSharedAccessKey' failed with message '{
"error": {
"code": "ParentResourceNotFound",
"message": "Can not perform requested operation on nested resource. Parent resource 'myServiceBus' not found."
}
}'
看起来它正在尝试在服务总线之前部署 Web 应用程序。我尝试了以下方法,但没有运气:
"myServiceBus"
"myServiceBusDeploy",
"[concat('Microsoft.Resources/deployments/', 'myServiceBusDeploy')]",
"[concat('Microsoft.ServiceBus/namespaces', 'myServiceBus')]"
"[resourceId('Microsoft.Resources/deployments', 'myServiceBusDeploy')]"
"[resourceId('Microsoft.ServiceBus/namespaces', 'myServiceBus')]"
我没有想法,不知道如何设置这两个链接模板之间的依赖关系。
更新:如果我在收到错误后再次部署我的模板,它将工作,因为服务总线已经在第一次部署中部署。所以,我很确定嵌套/链接的模板是可以的。
解决方案
正如 Gleb 所指出的,这里的问题是 listKeys 正在被立即评估(我们正在尝试修复 ARM 中的设计限制)。
要解决此问题,您可以执行以下两项操作之一:
1)不要将connstr传递给模板,只需传入resourceId并在Web应用程序部署中执行listKeys()。
2)在服务总线部署中使用(connstr的)部署输出,并引用()该部署输出。这将起作用,但它也会在嵌套部署上短路/验证,因此#1是一种更好的整体方法。
高温高压
推荐阅读
- python - 如何在mysql表中添加数据
- powershell - 使用 Powershell 将用户从多个 AD 组复制到新的 AD 组
- r - 如何将ggplot构面保存为单独的对象和文件
- javascript - 存在休息时响应文本始终为空事件
- wordpress - 我在博客中的内容又重复了一次
- python - Numpy数组重塑自定义python
- mysql - : 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在“app”附近使用的正确语法)
- javascript - 如何使用 pk 从 django 获取 url 到 javascript
- python - 计算多边形中的点并将结果写入 (Geo)Dataframe
- measurement - 使用压缩传感的荧光光谱测量?