I'm working on an Azure ARM template which will have a string parameter expecting a comma-separated list of email addresses. In the template I want to parse this and copy into an array of the object types required by the emailReceivers
property of the Microsoft.Insights/ActionGroups
resource type.
The input needs to be a single string because the value will be substituted by Octopus Deploy as part of our deployment pipeline.
The template I have works fine as long as at least one email address is supplied, but I want this value to be optional. Unfortunately when an empty string is supplied I get the following error:
The template 'copy' definition at line '0' and column '0' has an invalid copy count. The copy count must be postive integer value and cannot exceed '800'.
Clearly a zero-length array is not supported by these copy blocks so I'm wondering if anyone knows a workaround or cunning hack that will let me achieve what I want.
Here is a stripped down template example:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"emailAddresses": {
"type": "string",
"defaultValue": "one@email.com, two@email.com",
"metadata": {
"description": "Comma-separated list of email recipients."
}
}
},
"variables": {
"emailArray": "[if(equals(length(parameters('emailAddresses')), 0), json('[]'), split(parameters('emailAddresses'),','))]",
"copy": [
{
"name": "emailReceivers",
"count": "[length(variables('emailArray'))]",
"input": {
"name": "[concat('Email ', trim(variables('emailArray')[copyIndex('emailReceivers')]))]",
"emailAddress": "[trim(variables('emailArray')[copyIndex('emailReceivers')])]"
}
}
]
},
"resources": [],
"outputs": {
"return": {
"type": "array",
"value": "[variables('emailReceivers')]"
}
}
}