Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
198 lines (198 sloc) 7.59 KB
/*
# Access granted under MIT Open Source License: https://en.wikipedia.org/wiki/MIT_License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Created by: Brent Stineman
#
# Description: This template will create an Azure SQL DB and its parent virtual server. It also creates a default
# firewall rule to allow Azure services to acces the database.
# This template is based on work done for the Nether project: https://github.com/microsoftdx/nether
#
# For more about these techniques, see: https://brentdacodemonkey.wordpress.com/2017/03/09/azure-resource-manager-template-tips-and-tricks/
#
# Modifications
# 2017/04/19 : Initial publication
#
*/
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlServerName": {
"type": "string",
"minLength": 3,
"maxLength": 63,
"metadata": {
"description": "Database server name (must be globally unique). only allows alpha characters and '-'. Cannot start or end with '-'."
}
},
"databaseName": {
"type": "string",
"minLength": 3,
"maxLength": 63,
"metadata": {
"description": "Database server name (must be globally unique). only allows alpha characters and '-'. Cannot start or end with '-'."
}
},
"databaseSKU": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Standard S1",
"Standard S2",
"Standard S3",
"Premium P1",
"Premium P2",
"Premium P4",
"Premium P6",
"Premium P11",
"Premium P15"
],
"metadata": {
"description": "Specifies the database pricing/performance."
}
},
"sqlAdministratorLogin": {
"type": "string",
"defaultValue": "sqladmin",
"metadata": {
"description": "The admin user of the SQL Server"
}
},
"sqlAdministratorPassword": {
"type": "securestring",
"metadata": {
"description": "The password of the admin user of the SQL Server"
}
}
},
"variables": {
"sqlDBServerName" : "[toLower(parameters('sqlServerName'))]",
"sqlResourceAPI": "2014-04-01",
/* The databaseSKU specified in the input parameter is translated into the proper edition via this array */
"databasePricingTiers" : {
"Basic" : {
"edition": "Basic",
"requestedServiceObjectiveName": "Basic"
},
"Standard" : {
"edition": "Standard",
"requestedServiceObjectiveName": "S0"
},
"Standard S1" : {
"edition": "Standard",
"requestedServiceObjectiveName": "S1"
},
"Standard S2" : {
"edition": "Standard",
"requestedServiceObjectiveName": "S2"
},
"Standard S3" : {
"edition": "Standard",
"requestedServiceObjectiveName": "S3"
},
"Premium P1" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P1"
},
"Premium P2" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P2"
},
"Premium P4" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P4"
},
"Premium P6" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P6"
},
"Premium P11" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P11"
},
"Premium P15" : {
"edition": "Premium",
"requestedServiceObjectiveName": "P15"
}
}
},
"resources": [
/* The Azure SQL Database host server
* This server is a management container for individual databases
*/
{
"type": "Microsoft.Sql/servers",
"name": "[variables('sqlDBServerName')]",
"apiVersion": "[variables('sqlResourceAPI')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "SqlServer"
},
"properties": {
"administratorLogin": "[parameters('sqlAdministratorLogin')]",
"administratorLoginPassword": "[parameters('sqlAdministratorPassword')]",
"version": "12.0"
},
"resources": [
/* a sample database */
{
"type": "databases",
"name": "[parameters('databaseName')]",
"apiVersion": "[variables('sqlResourceAPI')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('sqlDBServerName')]"
],
"tags": {
"displayName": "Database"
},
"properties": "[variables('databasePricingTiers')[parameters('databaseSKU')]]"
},
/* Create firewall rule to allow all Azure services to connect to the database */
{
"type": "firewallrules",
"name": "AllowAllWindowsAzureIps",
"apiVersion": "[variables('sqlResourceAPI')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('sqlDBServerName')]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
}
]
}
],
/* outputs:
* databaseServerFQDN: the hdatabase server host name (URI)
* databaseName: the database on the server for use by Nether
*/
"outputs": {
"databaseServerFQDN" : {
"type" : "string",
"value": "[reference(variables('sqlDBServerName')).fullyQualifiedDomainName]"
},
"databaseName" : {
"type" : "string",
"value": "[parameters('databaseName')]"
}
}
}