2

I was thinking to either define API version numbers it looks like I keep repeating in some template referenced in all of linked templates, but it looks as if I have trouble doing so and I'm not sure if this should be even possible let alone how to do it.

For instance, int azuredeploy-shared.json I could do something like

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "variables": {
    "apiVersion": {
        "resources": { "deployments": "2015-01-01" }
    }
  }
}

and in azuredeploy.json I could then use it like

resources": [
{
    "name": "someResource",
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "[variables('apiVersion').resources.deployments]",

The first stumbling block is there needs to be a resources section. It makes me wonder if I reference a wrong schema or should one be referenced at all. If I create something I regard as dummy resources and provided this idea works, how should the azuredeploy.json reference this file?

I could do something like "[concat(parameters('_artifactsLocation'), '/ProjectName/Templates/azuredeploy-shared-json', parameters('_artifactsLocationSasToken'))]" but I don't know where or how and should it still work. So, working pointers appreciated in this regard. I did saw How to pass variables between templates - ARM json, but unfortunately I didn't understand how should it work and neither the linked Azure example.

Community
  • 1
  • 1
Veksi
  • 3,556
  • 3
  • 30
  • 69
  • Just to make sure I understand your scenario... are you essentially trying to pull parametrers/variables from 2 json files - one with the shared values and one with values unique to that deployment? – bmoore-msft Apr 04 '16 at 15:30
  • @bmoore-msft I'm trying to create a file "constants", which I can "include" in other files and then reference the constants with some constant variable name. I noticed I have a lot of strings such as "apiVersion": "2015-01-01", which I'd like to update at once once the tooling doesn't complain, say, in this case about using *"2016-03-30"*. I'm afraid I've missed something simple. I've managed to "include" other fragments (using that `concat` thing there) and pass parameters to them, but not *from them*. Maybe I should somehow utilize the `outputs` directive..? – Veksi Apr 04 '16 at 18:07

1 Answers1

3

Ok, I think you could do this using deployment output... it seems like there might be a simpler solution but I can't think of one for as much as I understand about your scenario.

1) deploy a template containing all your constants and set those constants as outputs for that deployment

2) in the template deployment where you want to access them, use the reference function, eg

reference('/subscriptions/{GUID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}','2015-01-01').outputs.{nameOfConstant}.value]"

Just deploy step #1 again with the same deployment name to update the constants. Is that what you're after?

bmoore-msft
  • 8,376
  • 20
  • 22
  • I think outputs is the way to go. I've grown my template quite big, so need to break down it a bit and test. Thanks for confirming this! – Veksi Apr 09 '16 at 07:03
  • It might not be feasible if it contains secrets. – Shishir Gupta Jun 07 '22 at 05:33
  • For secrets you would use keyVault - also, since the OP azure app config store is available for these types of scenarios: https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview – bmoore-msft Jun 08 '22 at 23:52