首页 > 解决方案 > ARM 模板 - 在两个嵌套模板之间创建依赖关系

问题描述

我有两个嵌套部署:

一个用于部署托管标识的资源组 A。

第二个是资源组 B,它部署 Keyvault 并为资源组 A 中的 ManagedIdentity 设置访问策略。


我想让资源组 B 的嵌套部署依赖于资源组 A 的嵌套部署。 (我的主要模板是部署到资源组 C)


我努力了:

"dependsOn": [
                "[variables('resourceGroupADeploymentName')]"
              ],

但我一直失败:找不到资源组“A”下的资源“Microsoft.ManagedIdentity/userAssignedIdentities/managedIdentityA”。

过了一会儿,我看到在资源组 A 中创建了 ManagedIdentityA - 所以这意味着dependsOn 没有工作,并且 resourceGroupB 部署没有等待 ResourceGroupA 部署。

我也尝试过使用dependsOn resourceId,但它没有用。(并且还将dependsOn 添加到ResourceGroupB 中的实际KeyVault 资源部署中)


知道如何让资源组 B 中的资源依赖于资源组 A 中的资源吗?


这是我的 resourceGroupB 的 ARM 模板:

{
      "name": "resourceGroupBDeploymentName",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "[variables('resourceDeploymentApiVersion')]",
      "resourceGroup": "[parameters('B')]",
      "subscriptionId": "[parameters('S')]",
      "dependsOn": [
            "[variables('resourceGroupADeploymentName')]"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.KeyVault/vaults/accessPolicies",
              "name": "[concat(parameters('deploymentKvName'), '/add')]",
              "apiVersion": "[variables('kvApiVersion')]",
              "properties": {
                "accessPolicies": [
                  {
                    "tenantId": "[parameters('S')]",
                    "objectId": "[reference(variables('ManagedIdentityResourceGroupA'), '2018-11-30').principalId]",
                    "permissions": {
                        "keys": [],
                        "secrets": [],
                        "certificates": [
                            "Get"
                        ]
                      }
                    }
                  ]
              }
            }           
            }          
          ]
        }
      }
    }

这是我的 resourceGroupA 的 ARM 模板:

{
      "name": "[variables('ManagedIdentityResourceGroupA')]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "[variables('resourceDeploymentApiVersion')]",
      "resourceGroup": "[parameters('A')]",
      "subscriptionId": "[parameters('S')]",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "name": "[variables('ManagedIdentityResourceGroupA')]",
              "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
              "apiVersion": "2018-11-30",
              "tags": {},
              "location": "[resourceGroup().location]"
            }
          ]
        }
      }
    },

标签: azure-resource-managerarm-template

解决方案


我不认为有办法解决这个问题。依赖项仅在同一个资源组中起作用。你可以使用部署脚本资源来运行一个脚本来检查状态并且可以作为一个dependsOn


推荐阅读