ARM 模板:无法访问对象数组作为资源模板的参数

ARM Template : Unable to access Array of object as a parameter to the resource Template

我正在尝试创建一个 ARM 模板来部署多个资源的多个实例。我需要创建以下资源列表:

  1. 10 项云服务
  2. 2 个密钥保管库
  3. 30 个存储帐户
  4. 30 个 Eventhub 命名空间

以上所有资源都必须在单个资源组下创建,但由于资源命名约定策略,资源名称必须通过 ParameterTemplate.json 传递,并且不能自动生成。

下面是用于创建多个存储帐户的参数和模板文件的片段。

但不知何故我无法访问模板资源部分中的参数值。

Parameter.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "StorageAccount": {
            "value": [
                {
                    "name": "test01",                    
                    "skuName": "Standard_LRS",                    
                    "kind" : "Storage"
                },
                {
                    "name": "test02",                    
                    "skuName": "Standard_LRS",                    
                    "kind" : "Storage"
                }
            ]
        }
    }
}

Template.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "StorageAccount": {
            "type": "array",
            "defaultValue": []
        }
    },
    "resources": [
        {
            "apiVersion": "2017-06-01",
            "type": "Microsoft.Storage/storageAccounts",                        
            "name": "[parameters('StorageAccount')[copyIndex()].name]",         
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "Standard_LRS"
            },
            "copy": { 
              "name": "StorageAccount",               
              "count": "[length(parameters('StorageAccount'))]",
            }, 
            "kind": "Storage",
            "properties": {}
        }
    ],
    "outputs": {}
}

请建议我对模板的任何改进,或其他实现要求的方法。

我刚刚测试了您的模板,它运行良好(而且看起来不错)。测试:

New-AzureRmResourceGroupDeployment -ResourceGroupName name -TemplateParameterFile params.json -TemplateFile template.json

ps。您忘记将 sku 和 kind 传入模板

"sku": {
    "name": "[parameters('StorageAccount')[copyIndex()].skuName]"
},
"kind": "[parameters('StorageAccount')[copyIndex()].kind]"