首页 > 解决方案 > 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')]"

我没有想法,不知道如何设置这两个链接模板之间的依赖关系。

更新:如果我在收到错误后再次部署我的模板,它将工作,因为服务总线已经在第一次部署中部署。所以,我很确定嵌套/链接的模板是可以的。

标签: azureazure-resource-managerarm-template

解决方案


正如 Gleb 所指出的,这里的问题是 listKeys 正在被立即评估(我们正在尝试修复 ARM 中的设计限制)。

要解决此问题,您可以执行以下两项操作之一:

1)不要将connstr传递给模板,只需传入resourceId并在Web应用程序部署中执行listKeys()。

2)在服务总线部署中使用(connstr的)部署输出,并引用()该部署输出。这将起作用,但它也会在嵌套部署上短路/验证,因此#1是一种更好的整体方法。

高温高压


推荐阅读