Search code examples
arraysazureazure-rm-template

ARM template array parameter


I have an ARM template with a web app alerting rule, where I want to be able to configure which e-mails get the alerts.

The snippet for the e-mail alerting action is this:

"action": {
    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
    "sendToServiceOwners": false,
    "customEmails": [
        "email1@example.com",
        "email2@example.com"
    ]
}

The same template is used for setting up production, test, and dev environments. So I would like to use a parameter for the e-mail alerting.

How can I generate an array to be used as the "customEmails" property based on either a comma separated string, or an array type parameter?

I have tried "customEmails": "[array(parameters('AlertEmailRecipients'))]", and also

"customEmails": [
    [array(parameters('AlertEmailRecipients'))]
]

but neither work. I don't know how to tell it that the "customEmails" property value should come from a parameter.


Solution

  • I found a solution. The main problem was that my comma separated list of e-mail addresses had a space after each comma.

    The way I have implemented it now is like this:

    Define a string parameter with a comma separated list of e-mail addresses. Don't have spaces in the list.

    Define a variable like this:

    "customEmails" : "[split(parameters('AlertEmailRecipients'), ',')]"
    

    and then reference that variable in the alerting action:

    "action": {
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
        "sendToServiceOwners": false,
        "customEmails": "[variables('customEmails')]"
    }
    

    The example actually does this, but doesn't make it clear the the list of e-mails can't contain spaces.