-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.bicep
196 lines (180 loc) · 5.07 KB
/
main.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
param virtualMachineAdminUserName string = 'azadmin'
@secure()
param virtualMachineAdminPassword string
param virtualMachineNamePrefix string = 'MyVM0'
param virtualMachineCount int = 3
param virtualMachineSize string = 'Standard_DS2_v2'
@allowed([
'Server2012R2'
'Server2016'
'Server2019'
])
param operatingSystem string = 'Server2019'
param availabilitySetName string = 'MyAvailabilitySet'
param dnsPrefixForPublicIP string = uniqueString(resourceGroup().id)
param location string = resourceGroup().location
var myVNETName = 'myVNET'
var myVNETPrefix = '10.0.0.0/16'
var myVNETSubnet1Name = 'Subnet1'
var myVNETSubnet1Prefix = '10.0.0.0/24'
var diagnosticStorageAccountName = 'diagst${uniqueString(resourceGroup().id)}'
var operatingSystemValues = {
Server2012R2: {
PublisherValue: 'MicrosoftWindowsServer'
OfferValue: 'WindowsServer'
SkuValue: '2012-R2-Datacenter'
}
Server2016: {
PublisherValue: 'MicrosoftWindowsServer'
OfferValue: 'WindowsServer'
SkuValue: '2016-Datacenter'
}
Server2019: {
PublisherValue: 'MicrosoftWindowsServer'
OfferValue: 'WindowsServer'
SkuValue: '2019-Datacenter'
}
}
var availabilitySetPlatformFaultDomainCount = 2
var availabilitySetPlatformUpdateDomainCount = 5
var networkSecurityGroupName = 'default-NSG'
resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
{
name: 'default-allow-3389'
properties: {
priority: 1000
access: 'Allow'
direction: 'Inbound'
destinationPortRange: '3389'
protocol: 'Tcp'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
}
}
]
}
}
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name: myVNETName
location: location
properties: {
addressSpace: {
addressPrefixes: [
myVNETPrefix
]
}
}
}
resource subNet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {
name: '${myVNETName}/${myVNETSubnet1Name}'
properties: {
addressPrefix: myVNETSubnet1Prefix
networkSecurityGroup: {
id: networkSecurityGroup.id
}
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2020-08-01-preview' = {
name: diagnosticStorageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource availabilitySet 'Microsoft.Compute/availabilitySets@2020-06-01' = {
name: availabilitySetName
location: location
properties: {
platformFaultDomainCount: availabilitySetPlatformFaultDomainCount
platformUpdateDomainCount: availabilitySetPlatformUpdateDomainCount
}
sku: {
name: 'Aligned'
}
}
resource virtualMachines 'Microsoft.Compute/virtualMachines@2020-06-01' = [for i in range(0, virtualMachineCount): {
name: '${virtualMachineNamePrefix}${i + 1}'
location: location
properties: {
hardwareProfile: {
vmSize: virtualMachineSize
}
storageProfile: {
imageReference: {
publisher: operatingSystemValues[operatingSystem].PublisherValue
offer: operatingSystemValues[operatingSystem].OfferValue
sku: operatingSystemValues[operatingSystem].SkuValue
version: 'latest'
}
osDisk: {
name: '${virtualMachineNamePrefix}${i + 1}'
createOption: 'FromImage'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
caching: 'ReadWrite'
}
}
osProfile: {
computerName: '${virtualMachineNamePrefix}${i + 1}'
adminUsername: virtualMachineAdminUserName
windowsConfiguration: {
provisionVMAgent: true
}
adminPassword: virtualMachineAdminPassword
}
networkProfile: {
networkInterfaces: [
{
id: resourceId('Microsoft.Network/networkInterfaces', '${virtualMachineNamePrefix}${i + 1}-NIC1')
}
]
}
availabilitySet: {
id: availabilitySet.id
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: storageAccount.properties.primaryEndpoints.blob
}
}
}
}]
resource networkInterfaces 'Microsoft.Network/networkInterfaces@2020-06-01' = [for i in range(0, virtualMachineCount): {
name: '${virtualMachineNamePrefix}${i + 1}-NIC1'
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: resourceId('Microsoft.Network/publicIPAddresses', '${virtualMachineNamePrefix}${i + 1}-PIP1')
}
subnet: {
id: subNet.id
}
}
}
]
enableIPForwarding: false
}
}]
resource publicIPAddresses 'Microsoft.Network/publicIPAddresses@2020-06-01' = [for i in range(0, virtualMachineCount): {
name: '${virtualMachineNamePrefix}${i + 1}-PIP1'
location: location
properties: {
publicIPAllocationMethod: 'Dynamic'
dnsSettings: {
domainNameLabel: '${dnsPrefixForPublicIP}${i + 1}'
}
}
}]