edwardwilson
11/12/2016 - 1:28 PM

Azure deployment template

Azure deployment template

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "ServicePlanSKU": {
      "value": {
        "name": "S1",
        "tier": "Standard"
      }
    },
    "ServicePlanSKUCapacity": {
      "value": 1
    },
    "DatabaseServerAdminLogin": {
      "value": "myadminusername"
    },
    "DatabasePlanSKU": {
      "value": {
        "name": "S0",
        "tier": "Standard"
      }
    }
  }
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "servicePlanSKUCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "maxValue": 2,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    },
    "servicePlanSKU": {
      "type": "object",
      "defaultValue": {
        "name": "S1",
        "tier": "Standard"
      },
      "allowedValues": [
        {
          "name": "S1",
          "tier": "Standard"
        },
        {
          "name": "S2",
          "tier": "Standard"
        },
        {
          "name": "S3",
          "tier": "Standard"
        }
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "databaseServerAdminLogin": {
      "type": "string",
      "minLength": 1,
      "metadata": {
        "description": "Describes database server admin username"
      }
    },
    "databaseServerAdminLoginPassword": {
      "type": "securestring"
    },
    "databasePlanSKU": {
      "type": "object",
      "defaultValue": {
        "name": "Basic",
        "tier": "Basic"
      },
      "allowedValues": [
        {
          "name": "Basic",
          "tier": "Basic"
        },
        {
          "name": "S0",
          "tier": "Standard"
        },
        {
          "name": "S1",
          "tier": "Standard"
        }
      ],
      "metadata": {
        "description": "Describes the performance level for Edition"
      }
    },
    "storageType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_ZRS"
      ]
    }
  },
  "variables": {
    "frontendAppName": "[toLower(concat(resourceGroup().name, '-Web'))]",
    "apiAppName": "[toLower(concat(resourceGroup().name, '-Api'))]",
    "servicePlanName": "[toLower(concat(resourceGroup().name, '-ServicePlan'))]",

    "databaseServerName": "[uniquestring(resourceGroup().id)]",
    "databaseName": "[uniquestring(resourceGroup().id)]",
    "stagingDatabaseName": "[concat(variables('databaseName'), '-staging')]",
    "storageName": "[uniquestring(resourceGroup().id)]",
    "keyVaultName": "[uniquestring(resourceGroup().id)]",

    "FrontEndSettings-NodeVersion": "7.0.0"
  },
  "resources": [
    {
      "name": "[variables('servicePlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "dependsOn": [],
      "tags": {
        "displayName": "frontendServicePlan"
      },
      "sku": {
        "name": "[parameters('servicePlanSKU').name]",
        "tier": "[parameters('servicePlanSKU').tier]",
        "capacity": "[parameters('servicePlanSKUCapacity')]"
      },
      "properties": {
        "name": "[variables('servicePlanName')]"
      }
    },
    {
      "name": "[variables('frontendAppName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('servicePlanName')))]": "Resource",
        "displayName": "frontendApp"
      },
      "properties": {
        "name": "[variables('frontendAppName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
      },
      "resources": [
        {
          "name": "slotconfignames",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]"
          ],
          "tags": {
            "displayName": "slotConfigNames",
            "description": "Setting names which will stick to slots"
          },
          "properties": {
            "connectionStringNames": [],
            "appSettingNames": [ "ApiUrl" ]
          }
        },
        {
          "name": "web",
          "type": "config",
          "apiVersion": "2015-08-01",
          "tags": {
            "displayName": "Config"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]"
          ],
          "properties": {
            "phpVersion": "off",
            "netFrameworkVersion": "v4.6"
          }
        },
        {
          "name": "appsettings",
          "apiVersion": "2015-08-01",
          "type": "config",
          "tags": {
            "displayName": "Settings"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]",
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]"
          ],
          "properties": {
            "WEBSITE_NODE_DEFAULT_VERSION": "[variables('frontEndSettings-NodeVersion')]",
            "ApiUrl": "[reference(concat('Microsoft.Web/Sites/', variables('apiAppName'))).defaultHostName]"
          }
        },
        {
          "name": "connectionstrings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]"
          ],
          "tags": {
            "displayName": "ConnectionStrings"
          },
          "properties": {

          }
        },
        {
          "name": "staging",
          "type": "slots",
          "apiVersion": "2015-08-01",
          "location": "[resourceGroup().location]",
          "tags": {
            "displayName": "Staging Slot"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]"
          ],
          "properties": {
          },
          "resources": [
            {
              "name": "web",
              "type": "config",
              "apiVersion": "2015-08-01",
              "tags": {
                "displayName": "Config"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('frontendAppName'), 'staging')]"
              ],
              "properties": {
                "phpVersion": "off",
                "netFrameworkVersion": "v4.6"
              }
            },
            {
              "name": "appsettings",
              "apiVersion": "2015-08-01",
              "type": "config",
              "tags": {
                "displayName": "Settings"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('frontendAppName'), 'Staging')]",
                "[resourceId('Microsoft.Web/Sites/slots', variables('apiAppName'), 'staging')]"
              ],
              "properties": {
                "WEBSITE_NODE_DEFAULT_VERSION": "[variables('frontEndSettings-NodeVersion')]",
                "ApiUrl": "[reference(resourceId('Microsoft.Web/Sites/slots', variables('apiAppName'), 'staging')).defaultHostName]"
              }
            },
            {
              "name": "connectionstrings",
              "type": "config",
              "apiVersion": "2015-08-01",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('frontendAppName'), 'Staging')]"
              ],
              "tags": {
                "displayName": "ConnectionStrings"
              },
              "properties": {

              }
            }
          ]
        }
      ]
    },

    {
      "name": "[variables('apiAppName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('servicePlanName')))]": "Resource",
        "displayName": "apiApp"
      },
      "properties": {
        "name": "[variables('apiAppName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
      },
      "resources": [
        {
          "name": "slotconfignames",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]"
          ],
          "tags": {
            "displayName": "slotConfigNames",
            "description": "Setting names which will stick to slots"
          },
          "properties": {
            "connectionStringNames": [ "ApplicationContext", "MarineContext", "MaintenanceContext", "VehicleContext", "AuthContext" ],
            "appSettingNames": [ "HostingEnvironmentDomainName" ]
          }
        },
        {
          "name": "web",
          "type": "config",
          "apiVersion": "2015-08-01",
          "tags": {
            "displayName": "config"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]"
          ],
          "properties": {
            "phpVersion": "off",
            "netFrameworkVersion": "v4.6"
          }
        },
        {
          "name": "appsettings",
          "apiVersion": "2015-08-01",
          "type": "config",
          "tags": {
            "displayName": "settings"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]",
            "[resourceId('Microsoft.Web/Sites', variables('frontendAppName'))]",
            "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageName'))]"
          ],
          "properties": {
            "BlobStorage.AccountName": "[variables('storageName')]",
            "BlobStorage.AccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageName')), '2016-01-01').keys[0].value]",

            "HostingBlobStoreEnvironmentDomainName": "[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageName'))).primaryEndpoints.blob]",
            "HostingEnvironmentDomainName": "[reference(concat('Microsoft.Web/Sites/', variables('frontendAppName'))).defaultHostName]"
          }
        },
        {
          "name": "connectionstrings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]",
            "[resourceId('Microsoft.Sql/servers/', variables('databaseServerName'))]"
          ],
          "tags": {
            "displayName": "connectionStrings"
          },
          "properties": {
            "ApplicationContext": {
              "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('databaseServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('databaseServerAdminLogin'), '@', variables('databaseServerName'), ';Password=', parameters('databaseServerAdminLoginPassword'), ';')]",
              "type": "SQLAzure"
            }
          }
        },
        {
          "name": "staging",
          "type": "slots",
          "apiVersion": "2015-08-01",
          "location": "[resourceGroup().location]",
          "tags": {
            "displayName": "stagingSlot"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('apiAppName'))]"
          ],
          "properties": {
          },
          "resources": [
            {
              "name": "web",
              "type": "config",
              "apiVersion": "2015-08-01",
              "tags": {
                "displayName": "config"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('apiAppName'), 'staging')]"
              ],
              "properties": {
                "phpVersion": "off",
                "netFrameworkVersion": "v4.6"
              }
            },
            {
              "name": "appsettings",
              "apiVersion": "2015-08-01",
              "type": "config",
              "tags": {
                "displayName": "settings"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('apiAppName'), 'staging')]",
                "[resourceId('Microsoft.Web/Sites/slots', variables('frontendAppName'), 'staging')]",
                "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageName'))]"
              ],
              "properties": {
                "BlobStorage.AccountName": "[variables('storageName')]",
                "BlobStorage.AccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageName')), '2016-01-01').keys[0].value]",

                "HostingBlobStoreEnvironmentDomainName": "[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageName'))).primaryEndpoints.blob]",
                "HostingEnvironmentDomainName": "[reference(resourceId('Microsoft.Web/Sites/slots', variables('frontendAppName'), 'staging')).defaultHostName]"
              }
            },
            {
              "name": "connectionstrings",
              "type": "config",
              "apiVersion": "2015-08-01",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/slots', variables('apiAppName'), 'staging')]",
                "[resourceId('Microsoft.Sql/servers/', variables('databaseServerName'))]"
              ],
              "tags": {
                "displayName": "connectionStrings"
              },
              "properties": {
                "ApplicationContext": {
                  "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('databaseServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('stagingDatabaseName'), ';User Id=', parameters('databaseServerAdminLogin'), '@', variables('databaseServerName'), ';Password=', parameters('databaseServerAdminLoginPassword'), ';')]",
                  "type": "SQLAzure"
                }
              }
            }
          ]
        }
      ]
    },
    {
      "name": "[variables('databaseServerName')]",
      "type": "Microsoft.Sql/servers",
      "location": "[resourceGroup().location]",
      "apiVersion": "2014-04-01-preview",
      "dependsOn": [],
      "tags": {
        "displayName": "databaseServer"
      },
      "properties": {
        "administratorLogin": "[parameters('databaseServerAdminLogin')]",
        "administratorLoginPassword": "[parameters('databaseServerAdminLoginPassword')]"
      },
      "resources": [
        {
          "type": "firewallrules",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('databaseServerName'))]"
          ],
          "location": "[resourceGroup().location]",
          "name": "AllowAllAzureIps",
          "properties": {
            "endIpAddress": "0.0.0.0",
            "startIpAddress": "0.0.0.0"
          }
        },
        {
          "name": "[variables('databaseName')]",
          "type": "databases",
          "location": "[resourceGroup().location]",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('databaseServerName'))]"
          ],
          "tags": {
            "displayName": "database"
          },
          "properties": {
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "edition": "[parameters('databasePlanSKU').tier]",
            "maxSizeBytes": "1073741824",
            "requestedServiceObjectiveName": "[parameters('databasePlanSKU').name]"
          },
          "resources": [
            {
              "name": "current",
              "type": "transparentDataEncryption",
              "dependsOn": [
                "[resourceId('Microsoft.Sql/servers/databases', variables('databaseServerName'), variables('databaseName'))]"
              ],
              "location": null,
              "apiVersion": "2014-04-01",
              "properties": {
                "status": "Enabled"
              }
            }
          ]
        },
        {
          "name": "[variables('stagingDatabaseName')]",
          "type": "databases",
          "location": "[resourceGroup().location]",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('databaseServerName'))]"
          ],
          "tags": {
            "displayName": "stagingDatabase"
          },
          "properties": {
            "collation": "SQL_Latin1_General_CP1_CI_AS",
            "edition": "[parameters('databasePlanSKU').tier]",
            "maxSizeBytes": "1073741824",
            "requestedServiceObjectiveName": "[parameters('databasePlanSKU').name]"
          },
          "resources": [
            {
              "name": "current",
              "type": "transparentDataEncryption",
              "dependsOn": [
                "[resourceId('Microsoft.Sql/servers/databases', variables('databaseServerName'), variables('stagingDatabaseName'))]"
              ],
              "location": null,
              "apiVersion": "2014-04-01",
              "properties": {
                "status": "Enabled"
              }
            }
          ]
        }
      ]
    },
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageName')]",
      "apiVersion": "2016-01-01",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "[parameters('storageType')]"
      },
      "kind": "Storage",
      "tags": {
        "displayName": "storage"
      },
      "properties": {
        "encryption": {
          "keySource": "Microsoft.Storage",
          "services": {
            "blob": {
              "enabled": true
            }
          }
        }
      }
    }
  ],
  "outputs": {
    "blobStorageUrl": {
      "value": "[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageName'))).primaryEndpoints.blob]",
      "type": "string"
    },
    "apiUrl": {
      "value": "[reference(concat('Microsoft.Web/Sites/', variables('apiAppName'))).defaultHostName]",
      "type": "string"
    },
    "webUrl": {
      "value": "[reference(concat('Microsoft.Web/Sites/', variables('frontendAppName'))).defaultHostName]",
      "type": "string"
    },
    "db": {
      "value": "[variables('databaseName')]",
      "type": "string"
    }
  }
}