Skip to content

Instantly share code, notes, and snippets.

@windoze
Created May 24, 2016 09:19
Show Gist options
  • Save windoze/0164ab3a190986e779a4da45ccbe5b5a to your computer and use it in GitHub Desktop.
Save windoze/0164ab3a190986e779a4da45ccbe5b5a to your computer and use it in GitHub Desktop.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "Admin username for VM"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Admin password for VM"
}
},
"newStorageAccountName": {
"type": "string",
"metadata": {
"description": "Unique storage account name. Must be between 3 and 24 characters in length and use numbers and lower-case letters only."
}
},
"numberOfInstances": {
"type": "int",
"defaultValue": 2,
"allowedValues": [
2,
3,
4,
5,
6,
7,
8,
9,
10
],
"metadata": {
"description": "Number of VMs to deploy (2-10)"
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2",
"allowedValues": [
"Standard_A3",
"Standard_A6",
"Standard_A7",
"Standard_A8",
"Standard_A9",
"Standard_A10",
"Standard_A11",
"Standard_D2",
"Standard_D3",
"Standard_D4",
"Standard_D11",
"Standard_D12",
"Standard_D13",
"Standard_D14"
],
"metadata": {
"description": "Size of the Virtual Machine."
}
},
"dnsNameforLBIP": {
"type": "string",
"metadata": {
"description": "DNS name for Load Balancer IP"
}
}
},
"variables": {
"imagePublisher": "OpenLogic",
"imageOffer": "CentOS",
"imageSKU": "7.1",
"customScriptFilePath": "https://gist.githubusercontent.com/windoze/fee73663e8defecf25fdc5e8c6a42c5e/raw/7c122bd90fd12ea2e4c5737a2ebcaddce36898b9/deploy.sh",
"customScriptCommandToExecute": "bash deploy.sh",
"publicIPAddressName": "myPublicIP",
"virtualNetworkName": "myVNET",
"availabilitySetName": "myAvSet",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
"addressPrefix": "10.0.0.0/16",
"subnet1Name": "Subnet-1",
"subnet1Prefix": "10.0.0.0/24",
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/', variables('subnet1Name'))]",
"subnet2Name": "Subnet-2",
"subnet2Prefix": "10.0.1.0/24",
"subnet2Ref": "[concat(variables('vnetID'),'/subnets/', variables('subnet2Name'))]",
"vmStorageAccountContainerName": "vhds",
"lbName": "myLB",
"lbID": "[resourceId('Microsoft.Network/loadBalancers',variables('lbName'))]",
"frontEndIPConfigID": "[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEnd')]",
"lbPoolID": "[concat(variables('lbID'),'/backendAddressPools/BackendPool1')]",
"lbProbeID": "[concat(variables('lbID'),'/probes/tcpProbe')]",
"publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[parameters('newStorageAccountName')]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "Standard_LRS"
}
},
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[variables('availabilitySetName')]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"properties": {}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnet1Name')]",
"properties": {
"addressPrefix": "[variables('subnet1Prefix')]"
}
},
{
"name": "[variables('subnet2Name')]",
"properties": {
"addressPrefix": "[variables('subnet2Prefix')]"
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameforLBIP')]"
}
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat('nic1', copyindex())]",
"location": "[resourceGroup().location]",
"copy": {
"name": "nicLoop",
"count": "[parameters('numberOfInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
"[concat('Microsoft.Network/loadBalancers/', variables('lbName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnet1Ref')]"
},
"loadBalancerBackendAddressPools": [
{
"id": "[concat(variables('lbID'), '/backendAddressPools/BackendPool1')]"
}
],
"loadBalancerInboundNatRules": [
{
"id": "[concat(variables('lbID'),'/inboundNatRules/ssh', copyindex())]"
}
]
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat('nic2', copyindex())]",
"location": "[resourceGroup().location]",
"copy": {
"name": "nicLoop",
"count": "[parameters('numberOfInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig2",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnet2Ref')]"
}
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"name": "[variables('lbName')]",
"type": "Microsoft.Network/loadBalancers",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
],
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"publicIPAddress": {
"id": "[variables('publicIPAddressID')]"
}
}
}
],
"backendAddressPools": [
{
"name": "BackendPool1"
}
],
"inboundNatRules": [
{
"name": "ssh0",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50000,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh1",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50001,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh2",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50002,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh3",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50003,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh4",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50004,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh5",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50005,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh6",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50006,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh7",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50007,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh8",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50008,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh9",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50009,
"backendPort": 22,
"enableFloatingIP": false
}
},
{
"name": "ssh10",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "tcp",
"frontendPort": 50010,
"backendPort": 22,
"enableFloatingIP": false
}
}
],
"loadBalancingRules": [
{
"name": "LBRule",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"backendAddressPool": {
"id": "[variables('lbPoolID')]"
},
"protocol": "tcp",
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 10,
"probe": {
"id": "[variables('lbProbeID')]"
}
}
}
],
"probes": [
{
"name": "tcpProbe",
"properties": {
"protocol": "tcp",
"port": 80,
"intervalInSeconds": "5",
"numberOfProbes": "2"
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat('myvm', copyIndex())]",
"location": "[resourceGroup().location]",
"copy": {
"name": "virtualMachineLoop",
"count": "[parameters('numberOfInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', 'nic1', copyIndex())]",
"[concat('Microsoft.Network/networkInterfaces/', 'nic2', copyIndex())]",
"[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]",
"[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]"
],
"properties": {
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]"
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat('vm', copyIndex())]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[variables('imageSKU')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.chinacloudapi.cn/vhds/','osdisk', copyIndex(), '.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"properties": {
"primary": true
},
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat('nic1', copyindex()))]"
},
{
"properties": {
"primary": false
},
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat('nic2', copyindex()))]"
}
]
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat('myvm', copyIndex(), '/extension')]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"copy": {
"name": "virtualMachineLoop",
"count": "[parameters('numberOfInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', 'myvm', copyIndex())]"
],
"properties": {
"publisher": "Microsoft.OSTCExtensions",
"type": "CustomScriptForLinux",
"typeHandlerVersion": "1.3",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[variables('customScriptFilePath')]"
],
"commandToExecute": "[concat(variables('customScriptCommandToExecute'), ' ', copyIndex(), ' ', parameters('numberOfInstances'))]"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment