1

We have an Azure ARM template, which is adding appsettings for a Microsoft.Web/site.

"resources": [
    {
        "apiVersion": "2016-03-01",
        "name": "myazurefunction", 
        "type": "Microsoft.Web/sites", 
        "properties": {
            "name": "myazurefunction", 
            "siteConfig": {
                "appSettings": [
{
    "name": "MY_SERVICE_URL", 
    "value": "[concat('https://myservice-', parameters('env'), '.domain.ca')]"
}
                ]    
            }
        }
    }
]

We also 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 template and its parameters favor convention over configuration. This is working nicely for the most part, and leads to the following MY_SERVICE_URL values.

The problem is that we want to break the convention for the dev environment. That is, we want it to have a MY_SERVICE_URL that looks something like this:

How can we configure the ARM template to break the convention for only one environment?

My first though is to use a conditional like this, but such an ARM function appears not to be available.

"name": "MY_SERVICE_URL", 
"value": "[parameters('env') -eq 'dev' 
    ? 'https://abc123.foo.bar.baz.ca' 
    :  concat('https://myservice-', parameters('env'), '.domain.ca')]"

2 Answers 2

2

just create a variable that would depend on the parameter:

"parameters": {
...
"DeploymentType": {
    "type": "string",
    "allowedValues": [
        "Dev",
        "Prod"
    ]
}
...
"variables": {
    "Dev": "https://some_service-ci.domain.com",
    "Prod": "https://abc123.foo.bar.baz.com",
    "DeploymentVariable": "[variables(parameters('DeploymentType'))]",
...
"appSettings": [
    "name": "MY_SERVICE_URL", 
    "value": "[variables('DeploymentVariable')]"
]
...

Ok, so how does this work. you pass in the parameter 'DeploymentType', it can be PROD or DEV. If you pass DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]", - this evaluates to "[variables('Dev')]" and gets the value of "Dev": "https://some_service-ci.domain.com",

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

1 Comment

sorry, fixed a typo and added comment @ShaunLuttin
0

For the example in the question, the answer ended up looking like this:

"variables": {
   "myServiceUrl_default": "[concat('https://myservice-', parameters('env'), '.domain.ca')]",
   "myServiceUrl_dev": "https://abc123.foo.bar.baz.ca",
   "myServiceUrl_ci": "[variables('myServiceUrl_default')]",
   "myServiceUrl_qa": "[variables('myServiceUrl_default')]",
   "myServiceUrl_prod": "[variables('myServiceUrl_default')]",
   "myServiceUrl": "[variables(concat('myServiceUrl_', 'parameters('env')'))]"  
},

...

"appSettings: [
   {
      "name": "MY_SERVICE_URL",
      "value": "[variables('myServiceUrl')]"
   }
]

Comments

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.