-
Notifications
You must be signed in to change notification settings - Fork 1
/
jumpbox.bicep
267 lines (237 loc) · 7.57 KB
/
jumpbox.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
@description('Specifies the location of AKS cluster.')
param location string = resourceGroup().location
@description('Specifies the id of the virtual network.')
param virtualNetworkId string
@description('Specifies the idof the subnet which contains the virtual machine.')
param vmSubnetId string
@description('Specifies the name of the virtual machine.')
param vmName string = 'TestVm'
@description('Specifies the size of the virtual machine.')
param vmSize string = 'Standard_DS3_v2'
@description('Specifies the image publisher of the disk image used to create the virtual machine.')
param imagePublisher string = 'Canonical'
@description('Specifies the offer of the platform image or marketplace image used to create the virtual machine.')
param imageOffer string = 'UbuntuServer'
@description('Specifies the Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version.')
param imageSku string = '18.04-LTS'
@allowed([
'sshPublicKey'
'password'
])
@description('Specifies the type of authentication when accessing the Virtual Machine. SSH key is recommended.')
param authenticationType string = 'password'
@description('Specifies the name of the administrator account of the virtual machine.')
param vmAdminUsername string
@description('Specifies the SSH Key or password for the virtual machine. SSH key is recommended.')
@secure()
param vmAdminPasswordOrKey string
@allowed([
'Premium_LRS'
'StandardSSD_LRS'
'Standard_LRS'
'UltraSSD_LRS'
])
@description('Specifies the storage account type for OS and data disk.')
param diskStorageAccounType string = 'Premium_LRS'
@minValue(0)
@maxValue(64)
@description('Specifies the number of data disks of the virtual machine.')
param numDataDisks int = 1
@description('Specifies the size in GB of the OS disk of the VM.')
param osDiskSize int = 50
@description('Specifies the size in GB of the OS disk of the virtual machine.')
param dataDiskSize int = 50
@description('Specifies the caching requirements for the data disks.')
param dataDiskCaching string = 'ReadWrite'
@description('Specifies the globally unique name for the storage account used to store the boot diagnostics logs of the virtual machine.')
param blobStorageAccountName string = 'blob${uniqueString(resourceGroup().id)}'
@description('Specifies the name of the private link to the boot diagnostics storage account.')
param blobStorageAccountPrivateEndpointName string = 'BlobStorageAccountPrivateEndpoint'
@description('Specifies the id of the Log Analytics Workspace.')
param logAnalyticsWorkspaceId string
var vmNicName = '${vmName}Nic'
var vmNicId = vmNic.id
var blobPublicDNSZoneForwarder = '.blob.${environment().suffixes.storage}'
var blobPrivateDnsZoneName = 'privatelink${blobPublicDNSZoneForwarder}'
var blobStorageAccountPrivateEndpointGroupName = 'blob'
var omsAgentForLinuxName = 'LogAnalytics'
var omsDependencyAgentForLinuxName = 'DependencyAgent'
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${vmAdminUsername}/.ssh/authorized_keys'
keyData: vmAdminPasswordOrKey
}
]
}
provisionVMAgent: true
}
var virtualNetworkName = last(split(virtualNetworkId, '/'))
var logAnalyticsWorkspaceName = last(split(logAnalyticsWorkspaceId, '/'))
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-10-01' existing = {
name: logAnalyticsWorkspaceName
}
resource blobStorageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = {
name: blobStorageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource vmNic 'Microsoft.Network/networkInterfaces@2020-08-01' = {
name: vmNicName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: vmSubnetId
}
}
}
]
}
}
resource virtualMachines 'Microsoft.Compute/virtualMachines@2020-12-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: vmName
adminUsername: vmAdminUsername
adminPassword: vmAdminPasswordOrKey
linuxConfiguration: ((authenticationType == 'password') ? null : linuxConfiguration)
}
storageProfile: {
imageReference: {
publisher: imagePublisher
offer: imageOffer
sku: imageSku
version: 'latest'
}
osDisk: {
name: '${vmName}_OSDisk'
caching: 'ReadWrite'
createOption: 'FromImage'
diskSizeGB: osDiskSize
managedDisk: {
storageAccountType: diskStorageAccounType
}
}
dataDisks: [for j in range(0, numDataDisks): {
caching: dataDiskCaching
diskSizeGB: dataDiskSize
lun: j
name: '${vmName}-DataDisk${j}'
createOption: 'Empty'
managedDisk: {
storageAccountType: diskStorageAccounType
}
}]
}
networkProfile: {
networkInterfaces: [
{
id: vmNic.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: blobStorageAccount.properties.primaryEndpoints.blob
}
}
}
}
resource omsAgentForLinux 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = {
parent: virtualMachines
name: '${omsAgentForLinuxName}'
location: location
properties: {
publisher: 'Microsoft.EnterpriseCloud.Monitoring'
type: 'OmsAgentForLinux'
typeHandlerVersion: '1.13'
settings: {
workspaceId: logAnalyticsWorkspace.properties.customerId
stopOnMultipleConnections: false
}
protectedSettings: {
workspaceKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
resource omsDependencyAgentForLinux 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = {
parent: virtualMachines
name: '${omsDependencyAgentForLinuxName}'
location: location
properties: {
publisher: 'Microsoft.Azure.Monitoring.DependencyAgent'
type: 'DependencyAgentLinux'
typeHandlerVersion: '9.10'
autoUpgradeMinorVersion: true
}
}
resource blobPrivateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: blobPrivateDnsZoneName
location: 'global'
}
resource blobPrivateDnsZoneLinkToVirtualNetwork 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
parent: blobPrivateDnsZone
name: 'link_to_${toLower(virtualNetworkName)}'
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: virtualNetworkId
}
}
}
resource blobStorageAccountPrivateEndpoint 'Microsoft.Network/privateEndpoints@2020-08-01' = {
name: blobStorageAccountPrivateEndpointName
location: location
properties: {
privateLinkServiceConnections: [
{
name: blobStorageAccountPrivateEndpointName
properties: {
privateLinkServiceId: blobStorageAccount.id
groupIds: [
blobStorageAccountPrivateEndpointGroupName
]
}
}
]
subnet: {
id: vmSubnetId
}
customDnsConfigs: [
{
fqdn: concat(blobStorageAccountName, blobPublicDNSZoneForwarder)
}
]
}
}
resource blobPrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2020-08-01' = {
parent: blobStorageAccountPrivateEndpoint
name: '${blobStorageAccountPrivateEndpointGroupName}PrivateDnsZoneGroup'
properties: {
privateDnsZoneConfigs: [
{
name: 'dnsConfig'
properties: {
privateDnsZoneId: blobPrivateDnsZone.id
}
}
]
}
}