azure - 如何在ARM模板中添加多个访问策略

我正在尝试有条件地将访问策略添加到 Key Vault,问题是模板中不能有超过 1 个名称为 KeyVault/accessPolicies/add 的资源

这实际上是我想要实现的目标:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vaultName": {
            "type": "string"
        }
    },
    "resources": [
        {
            "condition": "[parameters('someCondition')]",
            "type": "Microsoft.KeyVault/vaults/accessPolicies",
            "name": "[concat(parameters('vaultName'), '/add')]",
            "apiVersion": "2016-10-01",
            "properties": {
                "accessPolicies": [
                    {
                        "tenantId": "[if(parameters('someCondition'), reference(variables('someAppServiceResourceId'), '2015-08-31-PREVIEW').tenantId, json('null'))]",
                        "objectId": "[if(parameters('someCondition'), reference(variables('someAppServiceResourceId'), '2015-08-31-PREVIEW').principalId, json('null'))]",
                        "permissions": {
                            "keys": ["all"],
                            "secrets": ["all"],
                            "certificates": ["all"],
                            "storage": ["all"]
                        }
                    }
                ]
            }
        },
        {
            "condition": "[parameters('otherCondition')]",
            "type": "Microsoft.KeyVault/vaults/accessPolicies",
            "name": "[concat(parameters('vaultName'), '/add')]",
            "apiVersion": "2016-10-01",
            "properties": {
                "accessPolicies": [
                    {
                        "tenantId": "[if(parameters('otherCondition'), reference(variables('someOTHERAppServiceResourceId'), '2015-08-31-PREVIEW').tenantId, json('null'))]",
                        "objectId": "[if(parameters('otherCondition'), reference(variables('someOTHERAppServiceResourceId'), '2015-08-31-PREVIEW').principalId, json('null'))]",
                        "permissions": {
                            "keys": ["all"],
                            "secrets": ["all"],
                            "certificates": ["all"],
                            "storage": ["all"]
                        }
                    }
                ]
            }
        }
    ],
    "outputs": {
    }
}

但是,在此部署中我只能拥有一个名为“KeyVaultName/add”的资源。

我想我可以有条件地在变量中构建访问策略数组并进行一些数组串联,但它不起作用,因为我在访问策略中使用引用()函数来获取租户和主体 ID .

最佳答案

为什么你认为这行不通?

"properties": {
    "copy": [
        {
            "name": "accessPolicies",
            "count": "[xxx]",
            "input": {
                "tenantId": "[if(parameters('otherCondition'), reference(variables('someOTHERAppServiceResourceId'), '2015-08-31-PREVIEW').tenantId, json('null'))]",
                "objectId": "[if(parameters('otherCondition'), reference(variables('someOTHERAppServiceResourceId'), '2015-08-31-PREVIEW').principalId, json('null'))]",
                "permissions": {
                    "keys": ["all"],
                    "secrets": ["all"],
                    "certificates": ["all"],
                    "storage": ["all"]
                }
            }
        }
    ]
}

https://stackoverflow.com/questions/61338977/

相关文章:

reactjs - 不变失败 : You should not use outside

windows - 在 Visual Studio Code 中更改工作区目录

tensorflow - 如何将 Tensorflow model.json 转换为 model.p

react-native - 使用 create-react-native-app 创建新项目时出现

c# - 如何使用预定义标记列表实现解析器/解释器?

dataframe - 在 DataFrame 上描述 vs printSchema 方法

python - tf.print 何时会按预期实际工作(即打印张量和变量的值)?

php - 从 laravel 中的数据库动态填充语言翻译数组

reactjs - 如何将 firebase 与 React 功能组件同步?

python - 写一个函数来乘以复数