Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
187 lines (186 sloc) 7.21 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 a single Azure hosted virtual machine and its companion resources like
# its NIC and an availability set. The template is designed to be flexible so you can pass the IP configuration
# for the NIC into the template, thus allowing the VM to be either public or private. The template can be called
# to create a single VM, or used multiple times (perhaps inside of a loop) to create multiple VMs in the
# availability set, perhaps behind an Azure Load Balancer.
#
# 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": {
"vmName": {
"type": "string",
"minLength": 3,
"maxLength": 15,
"metadata": {
"description": "Name of the VM."
}
},
"vmNamesuffix": {
"type": "string",
"maxLength": 2,
"metadata": {
"description": "A suffix to append to the end of the VM name (useful is looping)"
}
},
"windowsOSVersion": {
"type": "string",
"defaultValue": "2016-Datacenter",
"allowedValues": [
"2008-R2-SP1",
"2012-Datacenter",
"2012-R2-Datacenter",
"2016-Datacenter"
],
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_A1",
"allowedValues": [
"Standard_A1",
"Standard_A2",
"Standard_A1_v2",
"Standard_A2_v2",
"Standard_D1_v2",
"Standard_D2_v2"
],
"metadata": {
"description": "Specifies the pricing/performance. (only a sample set of allowed values is listed)"
}
},
"adminUser": {
"type": "string",
"metadata": {
"description": "The admin user of the VM"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "The password of the admin user of the VM"
}
},
"ipConfig": {
"type": "object",
"metadata": {
"description": "The IP configuration for the VM"
}
}
},
"variables": {
"vmName" : "[toLower(concat(parameters('vmName'),parameters('vmNamesuffix')))]",
"nicName": "[concat(variables('vmName'),'-nic')]",
"avsetName": "[toLower(concat(parameters('vmName'),'-avset'))]",
"vnetResourceAPI": "2016-09-01",
"vmResourceAPI": "2016-04-30-preview"
},
"resources": [
/* The NIC for the VM */
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"apiVersion": "[variables('vnetResourceAPI')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": "[parameters('ipConfig')]"
}
]
}
},
/* An availability set */
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[variables('avsetName')]",
"apiVersion": "[variables('vmResourceAPI')]",
"location": "[resourceGroup().location]",
"properties": {
"platformFaultDomainCount": 2,
"platformUpdateDomainCount": 5,
"managed": "true"
}
},
/* The VM */
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"apiVersion": "2016-04-30-preview",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]",
"[resourceId('Microsoft.Compute/availabilitySets/', variables('avsetName'))]"
],
"properties": {
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets',variables('avsetName'))]"
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUser')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"Name" : "[concat(variables('vmName'), '-OSDisk')]",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": false
}
}
}
}
],
/* outputs:
*/
"outputs": {
}
}