Azure ARM-将数组参数值传递给变量

时间:2018-11-30 11:05:19

标签: azure azure-resource-manager

我在这里尝试传递电子邮件值数组并将其引用为变量,以便它可以遍历每个值并进行部署。我的要求是单独保存参数文件,以便仅在任何更新的情况下才可以触摸参数文件(更多电子邮件详细信息)。我最终以这种方式尝试出错。请帮我过关。

错误::1.'在行'1'和列'487'处为模板参数'emailReceiverName'提供的值无效。' 2.“消息”:“至少一项资源部署操作失败。请列出部署操作以获取详细信息。

##### TemplateDeployment.json ######

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    "actionGroupName": {
      "type": "array",
      "metadata": {
        "description": "Unique name (within the Resource Group) for the Action group."
      }
    },
    "actionGroupShortName": {
      "type": "string",
      "defaultValue": "newActionGroup",
      "metadata": {
        "description": "Short name (maximum 12 characters) for the Action group."
      }
    },
    "emailReceiverName": {
      "type": "array",
      "metadata": {
        "description": "email receiver service Name."
      }
    },
    "emailReceiverAddress": {
      "type": "array",
      "metadata": {
        "description": "email receiver address."
      }
    }
  },
  "variables": {
          "actionGroups": [
        {
            "EmailName": "[array(parameters('emailReceiverName'))]",
            "EmailAddress": "[array(parameters('emailReceiverAddress'))]"
        }
          ]
  } ,
"resources": [
    {
    "type": "Microsoft.Insights/actionGroups",
    "apiVersion": "2018-03-01",
    "name": "actionname",
    "location": "Global",
    "properties": {
        "groupShortName": "short",
        "enabled": true,
        "copy": [
            {
                "name": "emailReceivers",
                "count": "[length(variables('actionGroups'))]",
                "input": {
                    "name": "[variables('actionGroups')[copyIndex('emailReceivers')].EmailName]",
                    "emailAddress": "[variables('actionGroups')[copyIndex('emailReceivers')].EmailAddress]"

                }

                }

        ]
    }
}
    ]
}

** ##### TemplateDeployment.json在此处######

## parameter.json ######## **
{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "actionGroupName": {
            "value": "actiongroupslb"
        },
        "actionGroupShortName": {
            "value": "agSLB"
        },
        "emailReceiverName": {
            "value": ["siva1","siva2",........]
        },
        "emailReceiverAddress": {
            "value": ["sa@ga.com","s@g.com",........]
        }

    }
}

1 个答案:

答案 0 :(得分:0)

好的,我不确定我是否正确理解您(抱歉)。但我认为您只需要这一点:

{
    "name": "emailReceivers",
    "count": "[length(parameters('emailReceiverName'))]",
    "input": {
        "name": "[(parameters('emailReceiverName')[copyIndex('emailReceivers')]]",
        "emailAddress": "[(parameters('emailReceiverAddress')[copyIndex('emailReceivers')]]"
    }
}

并删除此变量actionGroups