0
votes

My aim is to have an ARM template for all environments that I'm deploying to.

I would like to be able to define a variable as part of the release pipeline such as 'dev' or 'prod' and then have the ARM template use that as part of the deployed resource name.

For example:

myapi-dev-appserviceplan myapi-prod-appserviceplan

1

1 Answers

0
votes

Just create parameter and use them in the JSON file. Be careful there are "parameters" and "variables". In my case, I use parameter to create variable but sometimes, I use directly the parameter for the environment name (i.e: in my case environment is "dev", "uat", "prd" and injected in resource name)

Here is a full example which shows what you want to do

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": { 
        "environment": {
            "type": "String" 
        },
        "sku": {
            "type": "string",
            "defaultValue": "S1"
        }
    },
    "variables": {
        "webappPrefix": "lovelyfront",
      "location": "westeurope",
        "aiName": "[concat('ai-',variables('webappPrefix'), '-', parameters('environment'))]",
        "webappName": "[concat('wa-',variables('webappPrefix'), '-', parameters('environment'))]",
        "webappNameStagingSlot": "[concat(variables('webappName'), '/', 'staging')]",
        "appServicePlanName": "[concat('asp-',variables('webappPrefix'), '-', parameters('environment'))]",
        "storageAccountName": "[concat('stolovefront', toLower(parameters('environment')))]",
        "cognitiveEndpointName": "[concat('cog-',variables('webappPrefix'), '-', parameters('environment'))]",
        "signalRName": "[concat('sig-',variables('webappPrefix'), '-', parameters('environment'))]"
    },
  "resources": [
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('aiName')]",
      "type": "Microsoft.Insights/components",
      "location": "[variables('location')]",
      "properties": {
        "ApplicationId": "[variables('aiName')]"
      }
    },
    {
      "apiVersion": "2017-08-01",
      "type": "Microsoft.Web/serverfarms",
      "kind": "app",
      "name": "[variables('appServicePlanName')]",
      "location": "[variables('location')]",
      "properties": {},
      "dependsOn": [],
      "sku": {
        "name": "[parameters('sku')]"
      }
    },