0

I can't read from the doc: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates#variables if it is possible to create an array of complex objects. I think the "Variable-complex-type-value" is a bit vague.

Is it possible to create something like

    {
    "variables" : {
       "appsettings" : [ 
                {"name" :"1","value" :"v1"}, 
                {"name":"2","value" :"v2"}
        ]
} 

I want to be able to reference this in the appsettings of siteconfig, like this

{
... 
   properties:{
      "siteconfig" :{
          "appsettings" :"[variables('appsettings')]"
     }
  } 
... 
}

Is this even possible?

I am not in a position right now where I can try this at a computer so that is why I am asking here.

2
  • 1
    Yes it is possible and you should try ;-) Commented Jul 16, 2019 at 7:45
  • @Thomas thanks :) actually I kind of knew it was but I wanted to be sure. I know it is possible in the parameter section, but I haven't read anywhere that it is possible in the variable section. Commented Jul 16, 2019 at 8:08

1 Answer 1

1

Yes, it is possible.

To create multiple instances of a variable, use the copy property in the variables section.

You create an array of elements constructed from the value in the input property. You can use the copy property within a variable, or at the top level of the variables section. When using copyIndex inside a variable iteration, you must provide the name of the iteration.

"copy": [
      {
        "name": "top-level-object-array",
        "count": 5,
        "input": {
          "name": "[concat('myDataDisk', copyIndex('top-level-object-array', 1))]",
          "diskSizeGB": "1",
          "diskIndex": "[copyIndex('top-level-object-array')]"
        }
      },
      {
        "name": "top-level-integer-array",
        "count": 5,
        "input": "[copyIndex('top-level-integer-array')]"
      }
    ]

For more details, you could refer to this article.

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

3 Comments

I have read about the copy but I am not going to need it. I am explicitly asking for if it is possible to create an array of complex objects in the variables section.
Yes, you can. Please refer to this article.
Aaaah. firstProperty is doing a complex object in the variables section and using an array :)

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.