Jorn Theunissen
Jorn Theunissen

Reputation: 191

Azure ARM template - copy array to object array

I my ARM template I am trying to convert a string array of IP addresses in to an array that holds an object.

The ARM template should eventually look like this:

"ipRules": [
        {
          "value": "1.1.1.1",
          "action": "Allow"
        },
        {
          "value": "1.1.1.2",
          "action": "Allow"
        },
      ]

So to get an object notation like above, I tried to make a new variable using the Copy function to iterate the original Ip array:

"convertedAllowedIps": {
  "copy": [
    {
        "count": 2,
        "input": {
            "value": "[variables('allowedIps')[copyIndex()]]",
            "action": "Allow"
        }
    }
  ]
}

I assigned it like this:

"ipRules": "[variables('convertedAllowedIps')]",

This leads to an 'The language expression property could not be evaluated' error. What am I doing wrong here?

Upvotes: 2

Views: 1099

Answers (1)

4c74356b41
4c74356b41

Reputation: 72151

copy function looks like this:

"convertedAllowedIps": {
  "copy": [
      {
        "name": "something",
        "count": 2,
        "input": {
          "value": "[variables('allowedIps')[copyIndex('something')]]",
          "action": "Allow"
      }
    }
  ]  
}

and then you would reference it like this:

"[variables('convertedAllowedIps').something]"

Upvotes: 2

Related Questions