Home > Enterprise >  How to combine literal array value in my template with an array provided through parameters?
How to combine literal array value in my template with an array provided through parameters?

Time:11-11

In my ARM template to deploy a Web Site, I have some "appSettings" that I need to define in the template. I also have a parameter in the template that accepts another array of settings. I would like to combine this incoming array of settings with the ones I literally define in the template itself to produce the final "appSettings" array that I set in my ARM template. How can I achieve this?

Thanks!

CodePudding user response:

If those are two (or more) arrays that you would like to concatenate, then you can use the concat(arg1, arg2, arg3, ...) function - see official documentation. If those are more objects, then you can use union(arg1, arg2, arg3, ...).

The full list of ARM functions is available here.

The best way might be to define a variable which is composed of the concatenation of your different inputs.

CodePudding user response:

I believe I have a similar situation that was solved by using the union function. I chose to go with union because I had a set of default app settings defined in the ARM template and I also wanted to pass a parameter that would define new settings and possibly override some of the default settings. The union function "Returns a single array or object with all elements from the parameters. Duplicate values or keys are only included once." If you use concat, settings defined in both the default set and the parameter set will appear multiple times.

"variables": {
  "appSettingDefault": [...default values here...],
  "unionAppSettings": "[union(variables('appSettingDefault'), parameters('armAppSettings'))]",

Then just assign the variable to the resource property:

"siteConfig": {
  "appSettings": "[variables('unionAppSettings')]"
}
  • Related