Azure ARM-将数组参数值传递给变量 [英] Azure ARM- Passing array parameters values to Variables

查看:90
本文介绍了Azure ARM-将数组参数值传递给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am here trying to pass array of email values and reference it to variables, so that it can iterate over each value and deploy.My requirement is to keep parameter file separately so that i can touch parameter file only incase of any updation(more email details). Im ending up with errors trying this way. Please help me how can i pass.

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

Errors: 1.'The provided value for the template parameter 'emailReceiverName' at line '1' and column '487' is not valid.'. 2. "message": "At least one resource deployment operation failed. Please list deployment operations for details.

##### 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在此处######

**#####TemplateDeployment.json ends here ######

{
    "$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",........]
        }

    }
}

推荐答案

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

ok, I'm not sure I understand you correctly (sorry). But i think you just need this bit:

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

并删除此变量actionGroups

这篇关于Azure ARM-将数组参数值传递给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆