Skip to content

Instantly share code, notes, and snippets.

@BernieWhite
Created February 8, 2018 03:04
Show Gist options
  • Save BernieWhite/4c39e4010da495124167a84ab18a5098 to your computer and use it in GitHub Desktop.
Save BernieWhite/4c39e4010da495124167a84ab18a5098 to your computer and use it in GitHub Desktop.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmssLocation": {
"type": "string"
},
"vmssName": {
"type": "string"
},
"vmSku": {
"type": "string",
"defaultValue": "Standard_A2_v2"
},
"instanceCount": {
"type": "string",
"defaultValue": "1"
},
"vmOSSku": {
"type": "string",
"defaultValue": "Datacenter-Core-1709-with-Containers-smalldisk"
},
"singlePlacementGroup": {
"type": "string",
"defaultValue": "true"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"ipAllocationMethod": {
"type": "string",
"defaultValue": "Dynamic"
},
"pipLabel": {
"type": "string"
},
"vnetId": {
"type": "string"
},
"subnet": {
"type": "string"
},
"dscConfigurationUri": {
"type": "string"
},
"dscSasToken": {
"type": "string"
},
"project": {
"type": "string",
"defaultValue": "Activate Azure for IaaS"
},
"websitePackageUri": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"namingPrefix": "[toLower(substring(concat(parameters('vmssName'), uniqueString(resourceGroup().id)), 0, 9))]",
"networkApiVersion": "2017-06-01",
"loadBalancerName": "[concat(parameters('vmssName'), '-lb')]",
"vmssId": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', parameters('vmssName'))]",
"subnetId": "[concat(parameters('vnetId'),'/subnets/', parameters('subnet'))]",
"pipName": "[concat(parameters('vmssName'), '-pip')]"
},
"resources": [
{
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('pipName')]",
"location": "[parameters('vmssLocation')]",
"apiVersion": "2017-06-01",
"tags": {
"project": "[parameters('project')]"
},
"properties": {
"publicIPAllocationMethod": "[parameters('ipAllocationMethod')]",
"dnsSettings": {
"domainNameLabel": "[parameters('pipLabel')]"
}
}
},
{
"type": "Microsoft.Network/loadBalancers",
"name": "[variables('loadBalancerName')]",
"location": "[parameters('vmssLocation')]",
"apiVersion": "2017-06-01",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('pipName'))]"
],
"tags": {
"project": "[parameters('project')]"
},
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('pipName'))]"
}
}
}
],
"backendAddressPools": [
{
"name": "backend-web-pool"
}
],
"loadBalancingRules": [
{
"name": "http-lb-rule",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/frontendIPConfigurations/loadBalancerFrontEnd')]"
},
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "Tcp",
"loadDistribution": "Default",
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/backendAddressPools/backend-web-pool')]"
},
"probe": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/probes/http-lb-health-probe')]"
}
}
}
],
"probes": [
{
"name": "http-lb-health-probe",
"properties": {
"protocol": "Http",
"port": 80,
"requestPath": "/",
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
],
"inboundNatPools": [
{
"name": "natpool",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/frontendIPConfigurations/loadBalancerFrontEnd')]"
},
"protocol": "tcp",
"frontendPortRangeStart": "50000",
"frontendPortRangeEnd": "50119",
"backendPort": "3389"
}
}
]
}
},
{
"name": "[parameters('vmssName')]",
"type": "Microsoft.Compute/virtualMachineScaleSets",
"apiVersion": "2017-03-30",
"location": "[parameters('vmssLocation')]",
"dependsOn": [
"[concat('Microsoft.Network/loadBalancers/', variables('loadBalancerName'))]"
],
"sku": {
"name": "[parameters('vmSku')]",
"tier": "Standard",
"capacity": "[int(parameters('instanceCount'))]"
},
"tags": {
"service": "demo-app",
"role": "web",
"project": "[parameters('project')]"
},
"properties": {
"overprovision": true,
"upgradePolicy": {
"mode": "Automatic"
},
"singlePlacementGroup": "[parameters('singlePlacementGroup')]",
"virtualMachineProfile": {
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServerSemiAnnual",
"sku": "[parameters('vmOSSku')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"caching": "ReadWrite"
}
},
"osProfile": {
"computerNamePrefix": "[variables('namingPrefix')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"networkProfile": {
"networkInterfaceConfigurations": [
{
"name": "[concat(parameters('vmssName'), 'Nic')]",
"properties": {
"primary": true,
"ipConfigurations": [
{
"name": "[concat(parameters('vmssName'), 'IpConfig')]",
"properties": {
"subnet": {
"id": "[variables('subnetId')]"
},
"loadBalancerBackendAddressPools": [
{
"id": "[reference(variables('loadBalancerName'), variables('networkApiVersion')).backendAddressPools[0].id]"
}
],
"loadBalancerInboundNatPools": [
{
"id": "[reference(variables('loadBalancerName'), variables('networkApiVersion')).inboundNatPools[0].id]"
}
]
}
}
]
}
}
]
},
"extensionProfile": {
"extensions": [
{
"name": "Microsoft.Powershell.DSC",
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.20",
"autoUpgradeMinorVersion": true,
"settings": {
"configuration": {
"url": "[parameters('dscConfigurationUri')]",
"script": "webConfigurationCN.ps1",
"function": "webConfiguration"
},
"configurationArguments": {
"websitePackageUri": "[parameters('websitePackageUri')]"
}
},
"protectedSettings": {
"configurationUrlSasToken": "[parameters('dscSasToken')]"
}
}
}
]
}
}
}
},
{
"type": "Microsoft.Insights/autoscaleSettings",
"apiVersion": "2014-04-01",
"name": "[concat(variables('namingPrefix'), '-autoscale')]",
"location": "[parameters('vmssLocation')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachineScaleSets/', parameters('vmssName'))]"
],
"properties": {
"enabled": true,
"name": "[concat(variables('namingPrefix'), '-autoscale')]",
"targetResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', parameters('vmssName'))]",
"profiles": [
{
"name": "metric-scale-rule",
"capacity": {
"minimum": "1",
"maximum": "10",
"default": "1"
},
"rules": [
{
"metricTrigger": {
"metricName": "Percentage CPU",
"metricNamespace": "",
"metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', parameters('vmssName'))]",
"timeGrain": "PT1M",
"statistic": "Average",
"timeWindow": "PT5M",
"timeAggregation": "Average",
"operator": "GreaterThan",
"threshold": 75
},
"scaleAction": {
"direction": "Increase",
"type": "ChangeCount",
"value": "2",
"cooldown": "PT1M"
}
},
{
"metricTrigger": {
"metricName": "Percentage CPU",
"metricNamespace": "",
"metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', parameters('vmssName'))]",
"timeGrain": "PT1M",
"statistic": "Average",
"timeWindow": "PT5M",
"timeAggregation": "Average",
"operator": "LessThan",
"threshold": 25
},
"scaleAction": {
"direction": "Decrease",
"type": "ChangeCount",
"value": "1",
"cooldown": "PT1M"
}
}
]
}
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment