2
votes

When creating an arm template is it possible to concatenate each element of an array with a constant string? Below is my created parameter and the resource I am trying to create.

  "parameters": {

    "servicesNames": {
      "type": "array",
      "defaultValue": [
        "test-api-content",
        "test-svc-content"
      ]
    }
  }

    {
      "apiVersion": "2016-03-30",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[concat(parameters('servicesNames'),'pip')]",
      "location": "[resourceGroup().location]",
      "copy": {
        "name": "PIPaddresscopy",
        "count": "[length(parameters('servicesNames'))]"
      },
      "tags": {
        "displayName": "PublicIPAddress"
      }
   }

I would like the output of the resource name to be created with

"test-api-contentpip"

How ever I am getting the following error

The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an array

Please suggest how I can concatenate each value of the element

2

2 Answers

3
votes

Just to add to existing answer (as it is a bit unclear in my opinion).

What you are trying to do with your code - concatenate array with a string, and what you need to do is concatenate each element of the array with string.

There's a copyIndex() function that represent current iteration of the loop. and you can use array[number] to access specific member of the array. so

parameters('servicesNames')[copyIndex()]

means parameters('servicesNames')[0] and parameters('servicesNames')[1] in your case. That would effectively mean you've iterated over this array.

0
votes

You can concatenate each value of the element by modifying your name property for your publicIpAddress resource as below.

"name": "[concat(parameters('servicesNames')[copyIndex()], 'pip')]",

copyIndex:

This function is always used with a copy object.

If no value is provided for offset, the current iteration value is returned. The iteration value starts at zero.