-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-hub-s2s.bicep
354 lines (320 loc) · 8.15 KB
/
main-hub-s2s.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
@description('Username for the Virtual Machine.')
param adminUsername string = 'AzureAdmin'
@description('Password for the Virtual Machine.')
param adminPassword string = 'flowtest-2023'
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Number of VNETs and VMs to deploy')
@minValue(1)
@maxValue(254)
param copies int = 10
param vmsize string = 'Standard_D2s_v5'
@description('Prefix Name of VNETs')
param virtualNetworkName string = 'flow-vnet-'
param virtualNetworkTagGr1 string = 'Production'
param virtualNetworkTagGr2 string = 'Development'
@description('Name of the resource group')
param rgName string = resourceGroup().name
@description('remote desktop source address')
param sourceIPaddressRDP string = '217.121.228.158'
@description('Name of the subnet to create in the virtual network')
param subnetName string = 'vmSubnet'
param gwsubnetName string = 'GatewaySubnet'
param bastionsubnetName string = 'AzureBastionSubnet'
@description('Prefix name of the nic of the vm')
param nicName string = 'VMNic-'
@description('Prefix name of the nic of the vm')
param vmName string = 'VM-'
@description('Flow log storage account name')
param flowlogSt_name string = 'flowlog${resourceGroup().name}'
@description('Flow log name')
param flowlog_name string = 'flowlog'
@description('Network watcher name')
param networkwatcher_name string = 'NetworkWatcher_${location}'
//var customImageId = '/subscriptions/0245be41-c89b-4b46-a3cc-a705c90cd1e8/resourceGroups/image-gallery-rg/providers/Microsoft.Compute/galleries/mddimagegallery/images/windows2019-networktools/versions/2.0.0'
var imagePublisher = 'MicrosoftWindowsServer'
var imageOffer = 'WindowsServer'
var imageSku = '2022-Datacenter'
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-09-01' = [for i in range(0, copies): {
name: '${virtualNetworkName}${i}'
location: location
tags:{
group: (i<copies/2 ? virtualNetworkTagGr1 : virtualNetworkTagGr2)
}
properties: {
addressSpace: {
addressPrefixes: [
'10.0.${i}.0/24'
]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: '10.0.${i}.0/25'
delegations: []
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
networkSecurityGroup: {
id: flownsg.id
}
}
}
{
name: gwsubnetName
properties: {
addressPrefix: '10.0.${i}.128/27'
delegations: []
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
{
name: bastionsubnetName
properties: {
addressPrefix: '10.0.${i}.192/26'
delegations: []
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
]
virtualNetworkPeerings: [
{
name: 'lowhigh'
properties: {
allowVirtualNetworkAccess: true
allowForwardedTraffic: true
allowGatewayTransit: false
useRemoteGateways: false
remoteVirtualNetwork: {
id: resourceId(rgName, 'Microsoft.Network/virtualNetworks', '${virtualNetworkName}${(i<copies/2 ? (copies/2) : 0)}')
}
}
}
{
name: 'highlow'
properties: {
allowVirtualNetworkAccess: true
allowForwardedTraffic: true
allowGatewayTransit: false
useRemoteGateways: false
remoteVirtualNetwork: {
id: resourceId(rgName, 'Microsoft.Network/virtualNetworks', '${virtualNetworkName}${(i<copies/2 ? 0 : (copies/2))}')
}
}
}
]
}
}]
resource flownsg 'Microsoft.Network/networkSecurityGroups@2022-09-01' = {
name: 'anvm-nsg'
location: location
properties: {
securityRules: [
{
name: 'denyRFC1918-out'
properties: {
priority: 150
protocol: '*'
access: 'Deny'
direction: 'Outbound'
destinationAddressPrefixes: [
'10.0.0.0/8'
'172.16.0.0/12'
'192.168.0.0/24'
]
destinationPortRange: '*'
sourceAddressPrefix: '*'
sourcePortRange:'*'
}
}
]
}
}
resource flowlogst 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: flowlogSt_name
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource hubbastion 'Microsoft.Network/bastionHosts@2022-09-01' = {
name: 'hubbastion-0'
dependsOn:[
bastionpip
virtualNetwork
]
location: location
sku: {
name: 'Standard'
}
properties: {
enableShareableLink: true
enableIpConnect: true
ipConfigurations: [
{
name: 'ipConf'
properties: {
publicIPAddress: {
id: bastionpip.id
}
subnet: {
id: resourceId(rgName, 'Microsoft.Network/virtualNetworks/subnets', 'flow-vnet-0', bastionsubnetName)
}
}
}
]
}
}
resource bastionpip 'Microsoft.Network/publicIPAddresses@2022-09-01' = {
name: 'hubbastionpip'
location: location
sku: {
name: 'Standard'
}
zones:[
'1'
'2'
'3'
]
properties: {
publicIPAllocationMethod: 'Static'
}
}
resource hubgw 'Microsoft.Network/virtualNetworkGateways@2022-09-01' = [for i in [0,copies/2]:{
name: 'hubgw-${i}'
location: location
tags:{
group: (i<copies/2 ? virtualNetworkTagGr1 : virtualNetworkTagGr2)
}
dependsOn: [
hubgwpubip
virtualNetwork
]
properties: {
sku: {
name: 'VpnGw1AZ'
tier: 'VpnGw1AZ'
}
gatewayType: 'Vpn'
vpnType: 'RouteBased'
enablePrivateIpAddress: true
activeActive: false
enableBgp: true
bgpSettings: {
asn: 64000+i
}
ipConfigurations: [
{
name: 'default'
properties: {
publicIPAddress: {
id: resourceId(rgName, 'Microsoft.Network/publicIPAddresses', 'hubgwpip-${i}')
}
subnet: {
id: resourceId(rgName, 'Microsoft.Network/virtualNetworks/subnets', 'flow-vnet-${i}', gwsubnetName)
}
}
}
]
}
}]
resource connlowhigh 'Microsoft.Network/connections@2022-09-01' = {
name: 'conn-low-high'
location: location
properties: {
connectionType: 'Vnet2Vnet'
enableBgp: true
sharedKey: 'tunnelKey'
virtualNetworkGateway1: {
id: hubgw[0].id
properties: {
}
}
virtualNetworkGateway2:{
properties:{
}
id: hubgw[1].id
}
}
}
resource connhighlow 'Microsoft.Network/connections@2022-09-01' = {
name: 'conn-high-low'
location: location
properties: {
connectionType: 'Vnet2Vnet'
enableBgp: true
sharedKey: 'tunnelKey'
virtualNetworkGateway1: {
id: hubgw[1].id
properties: {
}
}
virtualNetworkGateway2:{
properties:{
}
id: hubgw[0].id
}
}
}
resource hubgwpubip 'Microsoft.Network/publicIPAddresses@2022-09-01' = [for i in [0,copies/2]:{
name: 'hubgwpip-${i}'
location: location
sku: {
tier: 'Regional'
name: 'Standard'
}
zones: [
'1'
'2'
'3'
]
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Static'
}
}]
module vm 'vm.bicep' = [for i in range(0, copies): {
name: 'vm${i}'
params: {
adminUsername: adminUsername
adminPassword: adminPassword
location: location
vmsize: vmsize
virtualNetworkName: virtualNetworkName
subnetName: subnetName
nicName: nicName
vmName: vmName
rgName: rgName
i: i
imagePublisher: imagePublisher
imageOffer: imageOffer
imageSku: imageSku
}
dependsOn: [
flownsg
flowlogst
virtualNetwork
]
}]
module flowlog 'flowlog.bicep' = {
name: 'flowlog'
scope: resourceGroup('NetworkWatcherRG')
params: {
flowlogSt_name: flowlogSt_name
networkwatcher_name: networkwatcher_name
location: location
sourceIPaddressRDP: sourceIPaddressRDP
rgName: rgName
virtualNetworkName: virtualNetworkName
subnetName: subnetName
copies: copies
}
dependsOn: [
flownsg
flowlogst
virtualNetwork
]
}