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

时间:2018-01-23 00:23:32

标签: arrays json azure arm-template

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

  1. 10云服务
  2. 2 Keyvaults
  3. 30个存储帐户
  4. 30 Eventhub命名空间
  5. 所有上述资源都必须在单个资源组下创建,但由于资源命名约定策略,资源名称必须通过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": {}
    }
    

    请建议我对模板或其他方法的任何改进以达到要求。

1 个答案:

答案 0 :(得分:0)

我刚测试了你的模板,它工作得非常好(看起来很好)。经测试:

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

PS。你忘了将sku传递给模板

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