-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VM scaleset with autoscaling example
- Loading branch information
Showing
2 changed files
with
502 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
param vmSku string { | ||
default: 'Standard_A1_v2' | ||
} | ||
param windowsOSVersion string { | ||
default: '2019-Datacenter' | ||
allowed: [ | ||
'2019-Datacenter' | ||
'2016-Datacenter' | ||
'2012-R2-Datacenter' | ||
'2012-Datacenter' | ||
] | ||
} | ||
param vmssName string { | ||
maxLength: 61 | ||
} | ||
param instanceCount int { | ||
maxValue: 100 | ||
minValue: 1 | ||
} | ||
param adminUsername string | ||
param adminPassword string { | ||
secure: true | ||
} | ||
param location string = resourceGroup().location | ||
|
||
var namingInfix = toLower(substring(concat(vmssName, uniqueString(resourceGroup().id)), 0, 9)) | ||
var longNamingInfix = toLower(vmssName) | ||
var addressPrefix = '10.0.0.0/16' | ||
var subnetPrefix = '10.0.0.0/24' | ||
var virtualNetworkName = '${namingInfix}vnet' | ||
var publicIPAddressName = '${namingInfix}pip' | ||
var subnetName = '${namingInfix}subnet' | ||
var loadBalancerName = '${namingInfix}lb' | ||
var natPoolName = '${namingInfix}natpool' | ||
var bePoolName = '${namingInfix}bepool' | ||
var natStartPort = 50000 | ||
var natEndPort = 50119 | ||
var natBackendPort = 3389 | ||
var nicname = '${namingInfix}nic' | ||
var ipConfigName = '${namingInfix}ipconfig' | ||
var osType = { | ||
publisher: 'MicrosoftWindowsServer' | ||
offer: 'WindowsServer' | ||
sku: windowsOSVersion | ||
version: 'latest' | ||
} | ||
var imageReference = osType | ||
|
||
resource virtualNetwork 'Microsoft.Network/virtualnetworks@2015-05-01-preview' = { | ||
name: virtualNetworkName | ||
location: location | ||
properties: { | ||
addressSpace: { | ||
addressPrefixes: [ | ||
addressPrefix | ||
] | ||
} | ||
subnets: [ | ||
{ | ||
name: subnetName | ||
properties: { | ||
addressPrefix: subnetPrefix | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
resource publicIP 'Microsoft.Network/publicIPAddresses@2020-06-01' = { | ||
name: publicIPAddressName | ||
location: location | ||
properties: { | ||
publicIPAllocationMethod: 'Dynamic' | ||
dnsSettings: { | ||
domainNameLabel: longNamingInfix | ||
} | ||
} | ||
} | ||
|
||
resource loadBalancer 'Microsoft.Network/loadBalancers@2020-06-01' = { | ||
name: loadBalancerName | ||
location: location | ||
properties: { | ||
frontendIPConfigurations: [ | ||
{ | ||
name: 'LoadBalancerFrontEnd' | ||
properties: { | ||
publicIPAddress: { | ||
id: publicIP.id | ||
} | ||
} | ||
} | ||
] | ||
backendAddressPools: [ | ||
{ | ||
name: bePoolName | ||
} | ||
] | ||
inboundNatPools: [ | ||
{ | ||
name: natPoolName | ||
properties: { | ||
frontendIPConfiguration: { | ||
id: resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', loadBalancerName, 'loadBalancerFrontEnd') | ||
} | ||
protocol: 'Tcp' | ||
frontendPortRangeStart: natStartPort | ||
frontendPortRangeEnd: natEndPort | ||
backendPort: natBackendPort | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2020-06-01' = { | ||
name: vmssName | ||
location: location | ||
sku: { | ||
name: vmSku | ||
tier: 'Standard' | ||
capacity: instanceCount | ||
} | ||
properties: { | ||
overprovision: true | ||
upgradePolicy: { | ||
mode: 'Manual' | ||
} | ||
virtualMachineProfile: { | ||
storageProfile: { | ||
osDisk: { | ||
createOption: 'FromImage' | ||
caching: 'ReadWrite' | ||
} | ||
imageReference: imageReference | ||
} | ||
osProfile: { | ||
computerNamePrefix: namingInfix | ||
adminUsername: adminUsername | ||
adminPassword: adminPassword | ||
} | ||
networkProfile: { | ||
networkInterfaceConfigurations: [ | ||
{ | ||
name: nicname | ||
properties: { | ||
primary: true | ||
ipConfigurations: [ | ||
{ | ||
name: ipConfigName | ||
properties: { | ||
subnet: { | ||
id: '${virtualNetwork.id}/subnets/${subnetName}' | ||
} | ||
loadBalancerBackendAddressPools: [ | ||
{ | ||
id: '${loadBalancer.id}/backendAddressPools/${bePoolName}' | ||
} | ||
] | ||
loadBalancerInboundNatPools: [ | ||
{ | ||
id: '${loadBalancer.id}/inboundNatPools/${natPoolName}' | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource autoScaleSettings 'microsoft.insights/autoscalesettings@2015-04-01' = { | ||
name: 'cpuautoscale' | ||
location: location | ||
properties: { | ||
name: 'cpuautoscale' | ||
targetResourceUri: vmss.id | ||
enabled: true | ||
profiles: [ | ||
{ | ||
name: 'Profile1' | ||
capacity: { | ||
minimum: '1' | ||
maximum: '10' | ||
default: '1' | ||
} | ||
rules: [ | ||
{ | ||
metricTrigger: { | ||
metricName: 'Percentage CPU' | ||
metricNamespace: '' | ||
metricResourceUri: vmss.id | ||
timeGrain: 'PT1M' | ||
timeWindow: 'PT5M' | ||
timeAggregation: 'Average' | ||
operator: 'GreaterThan' | ||
threshold: 50 | ||
statistic: 'Average' | ||
} | ||
scaleAction: { | ||
direction: 'Increase' | ||
type: 'ChangeCount' | ||
value: '1' | ||
cooldown: 'PT5M' | ||
} | ||
} | ||
{ | ||
metricTrigger: { | ||
metricName: 'Percentage CPU' | ||
metricNamespace: '' | ||
metricResourceUri: vmss.id | ||
timeGrain: 'PT1M' | ||
timeWindow: 'PT5M' | ||
timeAggregation: 'Average' | ||
operator: 'LessThan' | ||
threshold: 30 | ||
statistic: 'Average' | ||
} | ||
scaleAction: { | ||
direction: 'Decrease' | ||
type: 'ChangeCount' | ||
value: '1' | ||
cooldown: 'PT5M' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.