如何通过ARM模板将访问策略添加到不同资源组中的Keyvault

时间:2019-11-01 13:34:53

标签: azure azure-resource-manager azure-keyvault arm-template

我有3个共享1个Keyvault的应用程序。因此,我决定创建4个RG。用于3个应用程序的3个RG和用于密钥库和其他公共资源的1个RG。

一切正常。我可以通过自己的ARM模板创建3个应用程序,并通过自己的ARM模板创建Keyvault。

因此,当配置应用程序资源时,我想通过ARM模板在密钥库中为该应用程序添加访问策略。

   {
      "apiVersion": "2018-05-01",
      "name": "accesspolicies_deployment",
      "resourceGroup": "Common-RG",
      "type": "Microsoft.Resources/deployments",
      "dependsOn": [],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "type": "Microsoft.KeyVault/vaults/accessPolicies",
              "name": "[concat('kvdevwus', '/add')]",
              "apiVersion": "2018-02-14",
              "properties": {
                "accessPolicies": [
                  {
                    "tenantId": "[reference(variables('website'),'2018-02-01','Full').identity.tenantId]",
                    "objectId": "[reference(variables('website'),'2018-02-01','Full').identity.principalId]",
                    "permissions": {
                      "keys": [
                        "all"
                      ],
                      "secrets": [
                        "all"
                      ],
                      "certificates": [
                        "all"
                      ],
                      "storage": [
                        "all"
                      ]
                    }
                  }
                ]
              }
            }
          ],
          "outputs": {
            "principalId": {
              "type": "string",
              "value": "[reference(variables('website'),'2018-02-01','Full').identity.principalId]"
            }
          }
        }
      }
    }

我正在app s模板中使用以上模板。但是出现Resource Not Found错误。

设计本身是错误的还是我错过了任何东西?

2 个答案:

答案 0 :(得分:0)

必须肯定要了解更多代码,但是我怀疑您无法使用内联部署来完成所需的工作,必须使用链接模板。我们正在努力解决此问题,但尚不可用。

答案 1 :(得分:0)

我认为您在accesspolicies_deployment资源中缺少“ dependsOn”:[]。我的设置与您的设置相同,我在公共资源组中拥有密钥库,而我的Web应用程序在不同资源中。

在创建网站的ARM模板中,我还添加了accesspolicies_deployment,但添加了“ dependsOn”:[webapp01]以确保首先创建的网站以及创建键值访问策略之前创建的身份