I'm working on building Azure Resource Manager (ARM) templates and I'm having an issue that I can't work out. We have several development environments (sandbox, development, production, etc.) and I'm trying to wrap my head around how best to accomplish what I'm wanting.
I want to feed a parameters file that defines an environment parameter to identify which environment we're building. For example, here's one for the "dev" environment (there are more parameters, this is just minimal to be relevant).
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
}
}
}
I currently have inside the ARM template several variables that I want to be able to pull values out based on the environment, but I'm having trouble getting my ARM templates to build and the error messages are terrible ('malformed string' when validating using Azure CLI, and "BadRequest" is all I get when a build agent tries to deploy the resources).
If I have a variable defined as:
"sampleObject": {
"sbx": {
"value1": true,
"value2": true
},
"dev": {
"value1": true,
"value2": true
},
"prd": {
"value1": false,
"value2": true
}
}
I want to use these fields to further define variables "envValue1" and "envValue2" for use in defining resources later in the template, so I was trying something like this:
"environmentParams": "[variables('sampleObject')[parameters('environment')]]",
"envValue1": "[variables('environmentParams').value1]",
"envValue2": "[variables('environmentParams').value2]"
However the above doesn't appear to be working, and while I've used everything else in my templates before this is causing issues. Specifically I think it's the line
"environmentParams": "[variables('sampleObject')[parameters('environment')]]"
I can find several examples of people using "[variables('environmentParams').value1]"
to grab pieces of an object variable before, but I'm uncertain if I can pass in the parameters('environment)' piece like I have done before and I can't find anything using it this way.
What am I doing wrong? Is it possible to pass in the environment parameter to get a piece of an object? I have tried the following and nothing has worked thus far (testing creating the resource using Azure CLI).
"[variables('sampleObject')[parameters('environment')]]"
"[variables('sampleObject').[parameters('environment')]]"
If what I'm trying to do is not possible, how do people manage multiple environments? Do they just shove everything into a parameter file, making it difficult to see the differences between environments by looking at the ARM template?
"environmentParams": "[variables('sampleObject')[parameters('environment')]]",