Azure ARM- Passing array parameters values to Variables

六眼飞鱼酱① 提交于 2020-01-06 07:24:08

问题


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.

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 ends here ######

##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:


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')]]"
    }
}

and just drop this variable actionGroups



来源:https://stackoverflow.com/questions/53556300/azure-arm-passing-array-parameters-values-to-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!