RasmusW
RasmusW

Reputation: 3461

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": [
        "[email protected]",
        "[email protected]"
    ]
}

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.

Upvotes: 3

Views: 13592

Answers (2)

RasmusW
RasmusW

Reputation: 3461

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.

Upvotes: 3

rudi belt
rudi belt

Reputation: 201

I used the following using an array parameter:

parameter declaration:

"customEmails": {
      "type": "array",
      "metadata": {
        "description": "alert email addressess"
      }
}

in the parameters file:

"customEmails": {
      "value": [
        "[email protected]",
        "[email protected]"     
      ]
    }

usage:

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

Upvotes: 14

Related Questions