Shaun Luttin
Shaun Luttin

Reputation: 141512

Add an appsetting conditionally in an ARM template

This question requires both the key and value of an appsetting to be conditional. Set an appsetting value conditionally in an ARM template is a related question that requires only a conditional value.

We have four parameters.environment.json files. For instance, this is the content of parameters.dev.json.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01...",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "env": {
            "value": "dev"
        }
    }
}

The requirement is to add an API_KEY setting only in the dev environment and to have no such key or value in the ci, qa, and prod environments. Something like this comes to mind but of course does not work in an ARM template.

"appSettings": [
    {
        [if(parameters('env') eq 'dev')]
        {
            "name": "API_KEY", 
            "value": "[parameters('apikey')]"
        }    
        [endif()]
    }
]    

Upvotes: 1

Views: 1709

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

So, same approach, but pass in objects ;) If you need you can create another level of indirection (if you need to have more conditions).

"variables": {
"Appsettings1": {
    "name": "API_KEY1", 
    "value": "[parameters('apikey1')]",
    "existingsetting": "bla-bla"
},
"Appsettings2": {
    "name": "API_KEY2", 
    "value": "[parameters('apikey2')]",
    "existingsetting": "bla-bla"
},
"realAppsettings": "[variables(parameters('realAppsettings'))]" # < this pulls 
                  # Appsettings1 or Appsettings2 depending on the value or parameter
...
"appSettings": "[variables('realAppsettings')]"

Reference: Set an appsetting value conditionally in an ARM template

Upvotes: 3

Related Questions