5

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"
  },
]

1 Answer 1

10

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

Sign up to request clarification or add additional context in comments.

1 Comment

This worked. Thanks. Weird how it's called input, not output though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.