-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.bicep
270 lines (241 loc) · 6.73 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Resource name
param name string
// Resource suffix
param suffix string
// Resource location
param location string = resourceGroup().location
// Unique DNS Name for the Public IP used to access the Virtual Machine.
param publicIpDnsLabel string
// CIDR notation of the Virtual Networks.
param virtualNetworkAddressPrefix string = '10.0.0.0/16'
// CIDR notation of the Virtual Network Subnets.
param virtualNetworkSubnetPrefix string = '10.0.0.0/24'
// Username for the Virtual Machine.
param virtualMachineAdminUsername string
// Password for the Virtual Machine.
@secure()
param virtualMachineAdminPassword string
// Size of the Virtual Machine.
@allowed([
'Standard_D2s_v3'
'Standard_D4s_v3'
'Standard_D8s_v3'
])
param virtualMachineSize string = 'Standard_D8s_v3'
// The publisher of the Virtual Machine.
@allowed([
'MicrosoftVisualStudio'
'MicrosoftWindowsDesktop'
])
param virtualMachinePublisher string = 'MicrosoftWindowsDesktop'
// The offer of the Virtual Machine
@allowed([
'visualstudio2019latest'
'Windows-10'
])
param virtualMachineOffer string = 'Windows-10'
// The Windows version for the VM. This will pick a fully patched image of this given Windows version.
@allowed([
'vs-2019-comm-latest-ws2019'
'vs-2019-ent-latest-ws2019'
'20h1-pro-g2'
'20h1-ent-g2'
])
param virtualMachineSku string = '20h1-pro-g2'
// The URI of the PowerShell Custom Script.
param virtualMachineExtensionCustomScriptUri string = 'https://raw.githubusercontent.com/Azure/bicep/main/docs/examples/201/vm-windows-with-custom-script-extension/install.ps1'
var metadata = {
longName: '{0}-${name}-${(suffix ?? '') == '' ? '' : concat('-', suffix)}'
shortName: '{0}${replace(name, '-', '')}${(suffix ?? '') == '' ? '' : suffix}'
}
// Stroage Account
var storageAccount = {
name: replace(metadata.shortName, '{0}', 'st')
location: location
}
resource st 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccount.name
location: storageAccount.location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
// Public IP
var publicIp = {
name: replace(metadata.longName, '{0}', 'pip')
location: location
}
resource pip 'Microsoft.Network/publicIPAddresses@2020-06-01' = {
name: publicIp.name
location: publicIp.location
properties: {
publicIPAllocationMethod: 'Static'
dnsSettings: {
domainNameLabel: (publicIpDnsLabel ?? '') == '' ? replace(metadata.shortName, '{0}', 'vm') : publicIpDnsLabel
}
}
}
// Network Security Group
var networkSecurityGroup = {
name: replace(metadata.longName, '{0}', 'nsg')
location: location
securityRules: [
{
name: 'default-allow-3389'
properties: {
priority: 1000
access: 'Allow'
direction: 'Inbound'
protocol: 'TCP'
sourcePortRange: '*'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
destinationPortRange: 3389
}
}
]
}
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroup.name
location: networkSecurityGroup.location
properties: {
securityRules: networkSecurityGroup.securityRules
}
}
// Virtual Network
var subnetName = 'default'
var virtualNetwork = {
name: replace(metadata.longName, '{0}', 'vnet')
location: location
addressPrefixes: [
virtualNetworkAddressPrefix
]
subnets: [
{
name: subnetName
properties: {
addressPrefix: virtualNetworkSubnetPrefix
networkSecurityGroup: {
id: nsg.id
}
}
}
]
}
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name: virtualNetwork.name
location: virtualNetwork.location
properties: {
addressSpace: {
addressPrefixes: virtualNetwork.addressPrefixes
}
subnets: virtualNetwork.subnets
}
}
// Network Interface
var networkInterface = {
name: replace(metadata.longName, '{0}', 'nic')
location: location
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: pip.id
}
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnet.name, subnetName)
}
}
}
]
}
resource nic 'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: networkInterface.name
location: networkInterface.location
properties: {
ipConfigurations: networkInterface.ipConfigurations
}
}
// Virtual Machine
var virtualMachine = {
name: replace(metadata.shortName, '{0}', 'vm')
location: location
vmSize: virtualMachineSize
vmComputerName: replace(metadata.shortName, '{0}', 'vm')
vmAdminUsername: virtualMachineAdminUsername
vmAdminPassword: virtualMachineAdminPassword
vmImagePublisher: virtualMachinePublisher
vmImageOffer: virtualMachineOffer
vmImageSku: virtualMachineSku
vmOSDiskName: replace(metadata.longName, '{0}', 'osdisk')
vmDataDisks: []
networkInterfaces: [
{
id: nic.id
}
]
}
resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: virtualMachine.name
location: virtualMachine.location
properties: {
hardwareProfile: {
vmSize: virtualMachine.vmSize
}
osProfile: {
computerName: virtualMachine.vmComputerName
adminUsername: virtualMachine.vmAdminUsername
adminPassword: virtualMachine.vmAdminPassword
}
storageProfile: {
imageReference: {
publisher: virtualMachine.vmImagePublisher
offer: virtualMachine.vmImageOffer
sku: virtualMachine.vmImageSku
version: 'latest'
}
osDisk: {
name: virtualMachine.vmOSDiskName
caching: 'ReadWrite'
createOption: 'FromImage'
}
dataDisks: virtualMachine.vmDataDisks
}
networkProfile: {
networkInterfaces: virtualMachine.networkInterfaces
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: st.properties.primaryEndpoints.blob
}
}
}
}
// Virtual Machine Extensions - Custom Script
var virtualMachineExtensionCustomScript = {
name: '${vm.name}/config-app'
location: location
fileUris: [
virtualMachineExtensionCustomScriptUri
]
commandToExecute: 'powershell -ExecutionPolicy Unrestricted -File ./${last(split(virtualMachineExtensionCustomScriptUri, '/'))}'
}
resource vmext 'Microsoft.Compute/virtualMachines/extensions@2020-06-01' = {
name: virtualMachineExtensionCustomScript.name
location: virtualMachineExtensionCustomScript.location
properties: {
publisher: 'Microsoft.Compute'
type: 'CustomScriptExtension'
typeHandlerVersion: '1.10'
autoUpgradeMinorVersion: true
settings: {
fileUris: virtualMachineExtensionCustomScript.fileUris
commandToExecute: virtualMachineExtensionCustomScript.commandToExecute
}
protectedSettings: {}
}
}