﻿{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "webApiVersion": "2018-02-01",
    "cmWebAppNameTidy": "[toLower(trim(parameters('cmWebAppName')))]",
    "cdWebAppNameTidy": "[toLower(trim(parameters('cdWebAppName')))]"
  },
  "parameters": {
    "standard": {
      "type": "secureObject",
      "defaultValue": {
        "deploymentId": null,
        "location": null,
        "cmWebAppName": null,
        "cdWebAppName": null
      }
    },
    "extension": {
      "type": "secureObject",
      "defaultValue": {
        "msDeployPackageUrl": "$default"
      }
    },
    "deploymentId": {
      "type": "string",
      "defaultValue": "[coalesce(parameters('standard').deploymentId, resourceGroup().name)]"
    },
    "location": {
      "type": "string",
      "defaultValue": "[coalesce(parameters('standard').location, resourceGroup().location)]"
    },
    "cmWebAppName": {
      "type": "string",
      "defaultValue": "[coalesce(parameters('standard').cmWebAppName, concat(parameters('deploymentId'), '-cm'))]"
    },
    "cdWebAppName": {
      "type": "string",
      "defaultValue": "[coalesce(parameters('standard').cdWebAppName, concat(parameters('deploymentId'), '-cd'))]"
    },
    "msDeployPackageUrl": {
      "type": "securestring",
      "defaultValue": "[parameters('extension').msDeployPackageUrl]"
    }
  },
  "resources": [
    {
      "name": "[concat(variables('cmWebAppNameTidy'), '/', 'MSDeploy')]",
      "type": "Microsoft.Web/sites/extensions",
      "location": "[parameters('location')]",
      "apiVersion": "[variables('webApiVersion')]",
      "properties": {
        "addOnPackages": [
          {
            "packageUri": "[parameters('msDeployPackageUrl')]",
            "setParameters": {
              "Application Path": "[variables('cmWebAppNameTidy')]"
            }
          }
        ]
      }
    },
    {
      "name": "[concat(variables('cdWebAppNameTidy'), '/', 'MSDeploy')]",
      "type": "Microsoft.Web/sites/extensions",
      "location": "[parameters('location')]",
      "apiVersion": "[variables('webApiVersion')]",
      "properties": {
        "addOnPackages": [
          {
            "packageUri": "[parameters('msDeployPackageUrl')]",
            "setParameters": {
              "Application Path": "[variables('cdWebAppNameTidy')]"
            }
          }
        ]
      }
    }
  ]
}