Not sure if this functionality exists. I'm trying to transform a list of comma separated IP addresses from the Azure DevOps build parameters into an array of objects. So far it's only splitting a comma separated list into an array of strings, but the template needs an array of objects.
The parameter value is a comma separated list of IP Addresses. e.g. "192.168.0.1,192.168.0.2/32,127.0.0.1"
The ARM template would look like:
"variables": {
"ipaddresses": "[split(parameters('ipaddresses'), ',')]"
},
"resources": [
...
"ipRestrictions": "[stringArrToObjArr(variables('ipaddresses'))]" <--
...
]
And ideally function with the arrow above would yield a value for ipRestictions would be something like:
[
{
"ipAddress": "192.168.0.1"
},
{
"ipAddress": "192.168.0.2/32"
},
{
"ipAddress": "127.0.0.1"
},
]
you can use copy()
function to do that:
"variables": {
"ipaddresses": "[split(parameters('ipaddresses'), ',')]"
"copy": [
{
"name": "myVariable",
"count": "[length(variables('ipaddresses'))]",
"input": {
"ipAddress": "[variables('ipaddresses')[copyIndex('myVariable')]]"
}
}
]
},
this would return the desired object into a variable called myVariable
. if you want to rename it >> don't forget to rename it inside copyIndex()
as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With