-
Notifications
You must be signed in to change notification settings - Fork 490
/
hubNetworking.bicep
1076 lines (959 loc) · 39.1 KB
/
hubNetworking.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
metadata name = 'ALZ Bicep - Hub Networking Module'
metadata description = 'ALZ Bicep Module used to set up Hub Networking'
type subnetOptionsType = ({
@description('Name of subnet.')
name: string
@description('IP-address range for subnet.')
ipAddressRange: string
@description('Id of Network Security Group to associate with subnet.')
networkSecurityGroupId: string?
@description('Id of Route Table to associate with subnet.')
routeTableId: string?
@description('Name of the delegation to create for the subnet.')
delegation: string?
})[]
type lockType = {
@description('Optional. Specify the name of lock.')
name: string?
@description('Optional. The lock settings of the service.')
kind: ('CanNotDelete' | 'ReadOnly' | 'None')
@description('Optional. Notes about this lock.')
notes: string?
}
@sys.description('The Azure Region to deploy the resources into.')
param parLocation string = resourceGroup().location
@sys.description('Prefix value which will be prepended to all resource names.')
param parCompanyPrefix string = 'alz'
@sys.description('Name for Hub Network.')
param parHubNetworkName string = '${parCompanyPrefix}-hub-${parLocation}'
@sys.description('''Global Resource Lock Configuration used for all resources deployed in this module.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parGlobalResourceLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('The IP address range for Hub Network.')
param parHubNetworkAddressPrefix string = '10.10.0.0/16'
@sys.description('The name, IP address range, network security group, route table and delegation serviceName for each subnet in the virtual networks.')
param parSubnets subnetOptionsType = [
{
name: 'AzureBastionSubnet'
ipAddressRange: '10.10.15.0/24'
networkSecurityGroupId: ''
routeTableId: ''
}
{
name: 'GatewaySubnet'
ipAddressRange: '10.10.252.0/24'
networkSecurityGroupId: ''
routeTableId: ''
}
{
name: 'AzureFirewallSubnet'
ipAddressRange: '10.10.254.0/24'
networkSecurityGroupId: ''
routeTableId: ''
}
{
name: 'AzureFirewallManagementSubnet'
ipAddressRange: '10.10.253.0/24'
networkSecurityGroupId: ''
routeTableId: ''
}
]
@sys.description('Array of DNS Server IP addresses for VNet.')
param parDnsServerIps array = []
@sys.description('''Resource Lock Configuration for Virtual Network.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parVirtualNetworkLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Public IP Address SKU.')
@allowed([
'Basic'
'Standard'
])
param parPublicIpSku string = 'Standard'
@sys.description('Optional Prefix for Public IPs. Include a succedent dash if required. Example: prefix-')
param parPublicIpPrefix string = ''
@sys.description('Optional Suffix for Public IPs. Include a preceding dash if required. Example: -suffix')
param parPublicIpSuffix string = '-PublicIP'
@sys.description('Switch to enable/disable Azure Bastion deployment.')
param parAzBastionEnabled bool = true
@sys.description('Name Associated with Bastion Service.')
param parAzBastionName string = '${parCompanyPrefix}-bastion'
@sys.description('Azure Bastion SKU.')
@allowed([
'Basic'
'Standard'
])
param parAzBastionSku string = 'Standard'
@sys.description('Switch to enable/disable Bastion native client support. This is only supported when the Standard SKU is used for Bastion as documented here: https://learn.microsoft.com/azure/bastion/native-client')
param parAzBastionTunneling bool = false
@sys.description('Name for Azure Bastion Subnet NSG.')
param parAzBastionNsgName string = 'nsg-AzureBastionSubnet'
@sys.description('''Resource Lock Configuration for Bastion.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parBastionLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Switch to enable/disable DDoS Network Protection deployment.')
param parDdosEnabled bool = true
@sys.description('DDoS Plan Name.')
param parDdosPlanName string = '${parCompanyPrefix}-ddos-plan'
@sys.description('''Resource Lock Configuration for DDoS Plan.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parDdosLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Switch to enable/disable Azure Firewall deployment.')
param parAzFirewallEnabled bool = true
@sys.description('Azure Firewall Name.')
param parAzFirewallName string = '${parCompanyPrefix}-azfw-${parLocation}'
@sys.description('Set this to true for the initial deployment as one firewall policy is required. Set this to false in subsequent deployments if using custom policies.')
param parAzFirewallPoliciesEnabled bool = true
@sys.description('Azure Firewall Policies Name.')
param parAzFirewallPoliciesName string = '${parCompanyPrefix}-azfwpolicy-${parLocation}'
@sys.description('Azure Firewall Tier associated with the Firewall to deploy.')
@allowed([
'Basic'
'Standard'
'Premium'
])
param parAzFirewallTier string = 'Standard'
@sys.description('The Azure Firewall Threat Intelligence Mode. If not set, the default value is Alert.')
@allowed([
'Alert'
'Deny'
'Off'
])
param parAzFirewallIntelMode string = 'Alert'
@sys.description('Optional List of Custom Public IPs, which are assigned to firewalls ipConfigurations.')
param parAzFirewallCustomPublicIps array = []
@allowed([
'1'
'2'
'3'
])
@sys.description('Availability Zones to deploy the Azure Firewall across. Region must support Availability Zones to use. If it does not then leave empty.')
param parAzFirewallAvailabilityZones array = []
@allowed([
'1'
'2'
'3'
])
@sys.description('Availability Zones to deploy the VPN/ER PIP across. Region must support Availability Zones to use. If it does not then leave empty. Ensure that you select a zonal SKU for the ER/VPN Gateway if using Availability Zones for the PIP.')
param parAzErGatewayAvailabilityZones array = []
@allowed([
'1'
'2'
'3'
])
@sys.description('Availability Zones to deploy the VPN/ER PIP across. Region must support Availability Zones to use. If it does not then leave empty. Ensure that you select a zonal SKU for the ER/VPN Gateway if using Availability Zones for the PIP.')
param parAzVpnGatewayAvailabilityZones array = []
@sys.description('Switch to enable/disable Azure Firewall DNS Proxy.')
param parAzFirewallDnsProxyEnabled bool = true
@sys.description('Array of custom DNS servers used by Azure Firewall')
param parAzFirewallDnsServers array = []
@sys.description(''' Resource Lock Configuration for Azure Firewall.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parAzureFirewallLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Name of Route table to create for the default route of Hub.')
param parHubRouteTableName string = '${parCompanyPrefix}-hub-routetable'
@sys.description('Switch to enable/disable BGP Propagation on route table.')
param parDisableBgpRoutePropagation bool = false
@sys.description('''Resource Lock Configuration for Hub Route Table.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parHubRouteTableLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Switch to enable/disable Private DNS Zones deployment.')
param parPrivateDnsZonesEnabled bool = true
@sys.description('Resource Group Name for Private DNS Zones.')
param parPrivateDnsZonesResourceGroup string = resourceGroup().name
@sys.description('Array of DNS Zones to provision in Hub Virtual Network. Default: All known Azure Private DNS Zones')
param parPrivateDnsZones array = [
'privatelink.${toLower(parLocation)}.azmk8s.io'
'privatelink.${toLower(parLocation)}.batch.azure.com'
'privatelink.${toLower(parLocation)}.kusto.windows.net'
'privatelink.adf.azure.com'
'privatelink.afs.azure.net'
'privatelink.agentsvc.azure-automation.net'
'privatelink.analysis.windows.net'
'privatelink.api.azureml.ms'
'privatelink.azconfig.io'
'privatelink.azure-api.net'
'privatelink.azure-automation.net'
'privatelink.azurecr.io'
'privatelink.azure-devices.net'
'privatelink.azure-devices-provisioning.net'
'privatelink.azuredatabricks.net'
'privatelink.azurehdinsight.net'
'privatelink.azurehealthcareapis.com'
'privatelink.azurestaticapps.net'
'privatelink.azuresynapse.net'
'privatelink.azurewebsites.net'
'privatelink.batch.azure.com'
'privatelink.blob.core.windows.net'
'privatelink.cassandra.cosmos.azure.com'
'privatelink.cognitiveservices.azure.com'
'privatelink.database.windows.net'
'privatelink.datafactory.azure.net'
'privatelink.dev.azuresynapse.net'
'privatelink.dfs.core.windows.net'
'privatelink.dicom.azurehealthcareapis.com'
'privatelink.digitaltwins.azure.net'
'privatelink.directline.botframework.com'
'privatelink.documents.azure.com'
'privatelink.eventgrid.azure.net'
'privatelink.file.core.windows.net'
'privatelink.gremlin.cosmos.azure.com'
'privatelink.guestconfiguration.azure.com'
'privatelink.his.arc.azure.com'
'privatelink.dp.kubernetesconfiguration.azure.com'
'privatelink.managedhsm.azure.net'
'privatelink.mariadb.database.azure.com'
'privatelink.media.azure.net'
'privatelink.mongo.cosmos.azure.com'
'privatelink.monitor.azure.com'
'privatelink.mysql.database.azure.com'
'privatelink.notebooks.azure.net'
'privatelink.ods.opinsights.azure.com'
'privatelink.oms.opinsights.azure.com'
'privatelink.pbidedicated.windows.net'
'privatelink.postgres.database.azure.com'
'privatelink.prod.migration.windowsazure.com'
'privatelink.purview.azure.com'
'privatelink.purviewstudio.azure.com'
'privatelink.queue.core.windows.net'
'privatelink.redis.cache.windows.net'
'privatelink.redisenterprise.cache.azure.net'
'privatelink.search.windows.net'
'privatelink.service.signalr.net'
'privatelink.servicebus.windows.net'
'privatelink.siterecovery.windowsazure.com'
'privatelink.sql.azuresynapse.net'
'privatelink.table.core.windows.net'
'privatelink.table.cosmos.azure.com'
'privatelink.tip1.powerquery.microsoft.com'
'privatelink.token.botframework.com'
'privatelink.vaultcore.azure.net'
'privatelink.web.core.windows.net'
'privatelink.webpubsub.azure.com'
]
@sys.description('Set Parameter to false to skip the addition of a Private DNS Zone for Azure Backup.')
param parPrivateDnsZoneAutoMergeAzureBackupZone bool = true
@sys.description('Resource ID of Failover VNet for Private DNS Zone VNet Failover Links')
param parVirtualNetworkIdToLinkFailover string = ''
@sys.description('''Resource Lock Configuration for Private DNS Zone(s).
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parPrivateDNSZonesLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Switch to enable/disable VPN virtual network gateway deployment.')
param parVpnGatewayEnabled bool = true
//ASN must be 65515 if deploying VPN & ER for co-existence to work: https://docs.microsoft.com/en-us/azure/expressroute/expressroute-howto-coexist-resource-manager#limits-and-limitations
@sys.description('Configuration for VPN virtual network gateway to be deployed.')
param parVpnGatewayConfig object = {
name: '${parCompanyPrefix}-Vpn-Gateway'
gatewayType: 'Vpn'
sku: 'VpnGw1'
vpnType: 'RouteBased'
generation: 'Generation1'
enableBgp: false
activeActive: false
enableBgpRouteTranslationForNat: false
enableDnsForwarding: false
bgpPeeringAddress: ''
bgpsettings: {
asn: 65515
bgpPeeringAddress: ''
peerWeight: 5
}
vpnClientConfiguration: {}
}
@sys.description('Switch to enable/disable ExpressRoute virtual network gateway deployment.')
param parExpressRouteGatewayEnabled bool = true
@sys.description('Configuration for ExpressRoute virtual network gateway to be deployed.')
param parExpressRouteGatewayConfig object = {
name: '${parCompanyPrefix}-ExpressRoute-Gateway'
gatewayType: 'ExpressRoute'
sku: 'ErGw1AZ'
vpnType: 'RouteBased'
vpnGatewayGeneration: 'None'
enableBgp: false
activeActive: false
enableBgpRouteTranslationForNat: false
enableDnsForwarding: false
bgpPeeringAddress: ''
bgpsettings: {
asn: '65515'
bgpPeeringAddress: ''
peerWeight: '5'
}
}
@sys.description('''Resource Lock Configuration for ExpressRoute Virtual Network Gateway.
- `kind` - The lock settings of the service which can be CanNotDelete, ReadOnly, or None.
- `notes` - Notes about this lock.
''')
param parVirtualNetworkGatewayLock lockType = {
kind: 'None'
notes: 'This lock was created by the ALZ Bicep Hub Networking Module.'
}
@sys.description('Tags you would like to be applied to all resources in this module.')
param parTags object = {}
@sys.description('Set Parameter to true to Opt-out of deployment telemetry.')
param parTelemetryOptOut bool = false
@sys.description('Define outbound destination ports or ranges for SSH or RDP that you want to access from Azure Bastion.')
param parBastionOutboundSshRdpPorts array = [ '22', '3389' ]
var varSubnetMap = map(range(0, length(parSubnets)), i => {
name: parSubnets[i].name
ipAddressRange: parSubnets[i].ipAddressRange
networkSecurityGroupId: contains(parSubnets[i], 'networkSecurityGroupId') ? parSubnets[i].networkSecurityGroupId : ''
routeTableId: contains(parSubnets[i], 'routeTableId') ? parSubnets[i].routeTableId : ''
delegation: contains(parSubnets[i], 'delegation') ? parSubnets[i].delegation : ''
})
var varSubnetProperties = [for subnet in varSubnetMap: {
name: subnet.name
properties: {
addressPrefix: subnet.ipAddressRange
delegations: (empty(subnet.delegation)) ? null : [
{
name: subnet.delegation
properties: {
serviceName: subnet.delegation
}
}
]
networkSecurityGroup: (subnet.name == 'AzureBastionSubnet' && parAzBastionEnabled) ? {
id: '${resourceGroup().id}/providers/Microsoft.Network/networkSecurityGroups/${parAzBastionNsgName}'
} : (empty(subnet.networkSecurityGroupId)) ? null : {
id: subnet.networkSecurityGroupId
}
routeTable: (empty(subnet.routeTableId)) ? null : {
id: subnet.routeTableId
}
}
}]
var varVpnGwConfig = ((parVpnGatewayEnabled) && (!empty(parVpnGatewayConfig)) ? parVpnGatewayConfig : json('{"name": "noconfigVpn"}'))
var varErGwConfig = ((parExpressRouteGatewayEnabled) && !empty(parExpressRouteGatewayConfig) ? parExpressRouteGatewayConfig : json('{"name": "noconfigEr"}'))
var varGwConfig = [
varVpnGwConfig
varErGwConfig
]
// Customer Usage Attribution Id Telemetry
var varCuaid = '2686e846-5fdc-4d4f-b533-16dcb09d6e6c'
// ZTN Telemetry
var varZtnP1CuaId = '3ab23b1e-c5c5-42d4-b163-1402384ba2db'
var varZtnP1Trigger = (parDdosEnabled && parAzFirewallEnabled && (parAzFirewallTier == 'Premium')) ? true : false
var varAzFirewallUseCustomPublicIps = length(parAzFirewallCustomPublicIps) > 0
//DDos Protection plan will only be enabled if parDdosEnabled is true.
resource resDdosProtectionPlan 'Microsoft.Network/ddosProtectionPlans@2023-02-01' = if (parDdosEnabled) {
name: parDdosPlanName
location: parLocation
tags: parTags
}
// Create resource lock if parDdosEnabled is true and parGlobalResourceLock.kind != 'None' or if parDdosLock.kind != 'None'
resource resDDoSProtectionPlanLock 'Microsoft.Authorization/locks@2020-05-01' = if (parDdosEnabled && (parDdosLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resDdosProtectionPlan
name: parDdosLock.?name ?? '${resDdosProtectionPlan.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parDdosLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parDdosLock.?notes
}
}
resource resHubVnet 'Microsoft.Network/virtualNetworks@2023-02-01' = {
dependsOn: [
resBastionNsg
]
name: parHubNetworkName
location: parLocation
tags: parTags
properties: {
addressSpace: {
addressPrefixes: [
parHubNetworkAddressPrefix
]
}
dhcpOptions: {
dnsServers: parDnsServerIps
}
subnets: varSubnetProperties
enableDdosProtection: parDdosEnabled
ddosProtectionPlan: (parDdosEnabled) ? {
id: resDdosProtectionPlan.id
} : null
}
}
// Create a virtual network resource lock if parGlobalResourceLock.kind != 'None' or if parVirtualNetworkLock.kind != 'None'
resource resVirtualNetworkLock 'Microsoft.Authorization/locks@2020-05-01' = if (parVirtualNetworkLock.kind != 'None' || parGlobalResourceLock.kind != 'None') {
scope: resHubVnet
name: parVirtualNetworkLock.?name ?? '${resHubVnet.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parVirtualNetworkLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parVirtualNetworkLock.?notes
}
}
module modBastionPublicIp '../publicIp/publicIp.bicep' = if (parAzBastionEnabled) {
name: 'deploy-Bastion-Public-IP'
params: {
parLocation: parLocation
parPublicIpName: '${parPublicIpPrefix}${parAzBastionName}${parPublicIpSuffix}'
parPublicIpSku: {
name: parPublicIpSku
}
parPublicIpProperties: {
publicIpAddressVersion: 'IPv4'
publicIpAllocationMethod: 'Static'
}
parResourceLockConfig: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock : parBastionLock
parTags: parTags
parTelemetryOptOut: parTelemetryOptOut
}
}
resource resBastionSubnetRef 'Microsoft.Network/virtualNetworks/subnets@2023-02-01' existing = if (parAzBastionEnabled) {
parent: resHubVnet
name: 'AzureBastionSubnet'
}
resource resBastionNsg 'Microsoft.Network/networkSecurityGroups@2023-02-01' = if (parAzBastionEnabled) {
name: parAzBastionNsgName
location: parLocation
tags: parTags
properties: {
securityRules: [
// Inbound Rules
{
name: 'AllowHttpsInbound'
properties: {
access: 'Allow'
direction: 'Inbound'
priority: 120
sourceAddressPrefix: 'Internet'
destinationAddressPrefix: '*'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '443'
}
}
{
name: 'AllowGatewayManagerInbound'
properties: {
access: 'Allow'
direction: 'Inbound'
priority: 130
sourceAddressPrefix: 'GatewayManager'
destinationAddressPrefix: '*'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '443'
}
}
{
name: 'AllowAzureLoadBalancerInbound'
properties: {
access: 'Allow'
direction: 'Inbound'
priority: 140
sourceAddressPrefix: 'AzureLoadBalancer'
destinationAddressPrefix: '*'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '443'
}
}
{
name: 'AllowBastionHostCommunication'
properties: {
access: 'Allow'
direction: 'Inbound'
priority: 150
sourceAddressPrefix: 'VirtualNetwork'
destinationAddressPrefix: 'VirtualNetwork'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: [
'8080'
'5701'
]
}
}
{
name: 'DenyAllInbound'
properties: {
access: 'Deny'
direction: 'Inbound'
priority: 4096
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
protocol: '*'
sourcePortRange: '*'
destinationPortRange: '*'
}
}
// Outbound Rules
{
name: 'AllowSshRdpOutbound'
properties: {
access: 'Allow'
direction: 'Outbound'
priority: 100
sourceAddressPrefix: '*'
destinationAddressPrefix: 'VirtualNetwork'
protocol: '*'
sourcePortRange: '*'
destinationPortRanges: parBastionOutboundSshRdpPorts
}
}
{
name: 'AllowAzureCloudOutbound'
properties: {
access: 'Allow'
direction: 'Outbound'
priority: 110
sourceAddressPrefix: '*'
destinationAddressPrefix: 'AzureCloud'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '443'
}
}
{
name: 'AllowBastionCommunication'
properties: {
access: 'Allow'
direction: 'Outbound'
priority: 120
sourceAddressPrefix: 'VirtualNetwork'
destinationAddressPrefix: 'VirtualNetwork'
protocol: '*'
sourcePortRange: '*'
destinationPortRanges: [
'8080'
'5701'
]
}
}
{
name: 'AllowGetSessionInformation'
properties: {
access: 'Allow'
direction: 'Outbound'
priority: 130
sourceAddressPrefix: '*'
destinationAddressPrefix: 'Internet'
protocol: '*'
sourcePortRange: '*'
destinationPortRange: '80'
}
}
{
name: 'DenyAllOutbound'
properties: {
access: 'Deny'
direction: 'Outbound'
priority: 4096
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
protocol: '*'
sourcePortRange: '*'
destinationPortRange: '*'
}
}
]
}
}
// Create bastion nsg resource lock if parAzBastionEnbled is true and parGlobalResourceLock.kind != 'None' or if parBastionLock.kind != 'None'
resource resBastionNsgLock 'Microsoft.Authorization/locks@2020-05-01' = if (parAzBastionEnabled && (parBastionLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resBastionNsg
name: parBastionLock.?name ?? '${resBastionNsg.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parBastionLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parBastionLock.?notes
}
}
// AzureBastionSubnet is required to deploy Bastion service. This subnet must exist in the parsubnets array if you enable Bastion Service.
// There is a minimum subnet requirement of /27 prefix.
// If you are deploying standard this needs to be larger. https://docs.microsoft.com/en-us/azure/bastion/configuration-settings#subnet
resource resBastion 'Microsoft.Network/bastionHosts@2023-02-01' = if (parAzBastionEnabled) {
location: parLocation
name: parAzBastionName
tags: parTags
sku: {
name: parAzBastionSku
}
properties: {
dnsName: uniqueString(resourceGroup().id)
enableTunneling: (parAzBastionSku == 'Standard' && parAzBastionTunneling) ? parAzBastionTunneling : false
ipConfigurations: [
{
name: 'IpConf'
properties: {
subnet: {
id: resBastionSubnetRef.id
}
publicIPAddress: {
id: parAzBastionEnabled ? modBastionPublicIp.outputs.outPublicIpId : ''
}
}
}
]
}
}
// Create Bastion resource lock if parAzBastionEnabled is true and parGlobalResourceLock.kind != 'None' or if parBastionLock.kind != 'None'
resource resBastionLock 'Microsoft.Authorization/locks@2020-05-01' = if (parAzBastionEnabled && (parBastionLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resBastion
name: parBastionLock.?name ?? '${resBastion.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parBastionLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parBastionLock.?notes
}
}
resource resGatewaySubnetRef 'Microsoft.Network/virtualNetworks/subnets@2023-02-01' existing = if (parVpnGatewayEnabled || parExpressRouteGatewayEnabled ) {
parent: resHubVnet
name: 'GatewaySubnet'
}
module modGatewayPublicIp '../publicIp/publicIp.bicep' = [for (gateway, i) in varGwConfig: if ((gateway.name != 'noconfigVpn') && (gateway.name != 'noconfigEr')) {
name: 'deploy-Gateway-Public-IP-${i}'
params: {
parLocation: parLocation
parAvailabilityZones: toLower(gateway.gatewayType) == 'expressroute' ? parAzErGatewayAvailabilityZones : toLower(gateway.gatewayType) == 'vpn' ? parAzVpnGatewayAvailabilityZones : []
parPublicIpName: '${parPublicIpPrefix}${gateway.name}${parPublicIpSuffix}'
parPublicIpProperties: {
publicIpAddressVersion: 'IPv4'
publicIpAllocationMethod: 'Static'
}
parPublicIpSku: {
name: parPublicIpSku
}
parResourceLockConfig: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock : parVirtualNetworkGatewayLock
parTags: parTags
parTelemetryOptOut: parTelemetryOptOut
}
}]
//Minumum subnet size is /27 supporting documentation https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-about-vpn-gateway-settings#gwsub
resource resGateway 'Microsoft.Network/virtualNetworkGateways@2023-02-01' = [for (gateway, i) in varGwConfig: if ((gateway.name != 'noconfigVpn') && (gateway.name != 'noconfigEr')) {
name: gateway.name
location: parLocation
tags: parTags
properties: {
activeActive: gateway.activeActive
enableBgp: gateway.enableBgp
enableBgpRouteTranslationForNat: gateway.enableBgpRouteTranslationForNat
enableDnsForwarding: gateway.enableDnsForwarding
bgpSettings: (gateway.enableBgp) ? gateway.bgpSettings : null
gatewayType: gateway.gatewayType
vpnGatewayGeneration: (toLower(gateway.gatewayType) == 'vpn') ? gateway.generation : 'None'
vpnType: gateway.vpnType
sku: {
name: gateway.sku
tier: gateway.sku
}
vpnClientConfiguration: (toLower(gateway.gatewayType) == 'vpn') ? {
vpnClientAddressPool: contains(gateway.vpnClientConfiguration, 'vpnClientAddressPool') ? gateway.vpnClientConfiguration.vpnClientAddressPool : ''
vpnClientProtocols: contains(gateway.vpnClientConfiguration, 'vpnClientProtocols') ? gateway.vpnClientConfiguration.vpnClientProtocols : ''
vpnAuthenticationTypes: contains(gateway.vpnClientConfiguration, 'vpnAuthenticationTypes') ? gateway.vpnClientConfiguration.vpnAuthenticationTypes : ''
aadTenant: contains(gateway.vpnClientConfiguration, 'aadTenant') ? gateway.vpnClientConfiguration.aadTenant : ''
aadAudience: contains(gateway.vpnClientConfiguration, 'aadAudience') ? gateway.vpnClientConfiguration.aadAudience : ''
aadIssuer: contains(gateway.vpnClientConfiguration, 'aadIssuer') ? gateway.vpnClientConfiguration.aadIssuer : ''
vpnClientRootCertificates: contains(gateway.vpnClientConfiguration, 'vpnClientRootCertificates') ? gateway.vpnClientConfiguration.vpnClientRootCertificates : ''
radiusServerAddress: contains(gateway.vpnClientConfiguration, 'radiusServerAddress') ? gateway.vpnClientConfiguration.radiusServerAddress : ''
radiusServerSecret: contains(gateway.vpnClientConfiguration, 'radiusServerSecret') ? gateway.vpnClientConfiguration.radiusServerSecret : ''
} : null
ipConfigurations: [
{
id: resHubVnet.id
name: 'vnetGatewayConfig'
properties: {
publicIPAddress: {
id: (((gateway.name != 'noconfigVpn') && (gateway.name != 'noconfigEr')) ? modGatewayPublicIp[i].outputs.outPublicIpId : 'na')
}
subnet: {
id: resGatewaySubnetRef.id
}
}
}
]
}
}]
// Create a Virtual Network Gateway resource lock if gateway.name is not equal to noconfigVpn or noconfigEr and parGlobalResourceLock.kind != 'None' or if parVirtualNetworkGatewayLock.kind != 'None'
resource resVirtualNetworkGatewayLock 'Microsoft.Authorization/locks@2020-05-01' = [for (gateway, i) in varGwConfig: if ((gateway.name != 'noconfigVpn') && (gateway.name != 'noconfigEr') && (parVirtualNetworkGatewayLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resGateway[i]
name: parVirtualNetworkGatewayLock.?name ?? '${resGateway[i].name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parVirtualNetworkGatewayLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parVirtualNetworkGatewayLock.?notes
}
}]
resource resAzureFirewallSubnetRef 'Microsoft.Network/virtualNetworks/subnets@2023-02-01' existing = if (parAzFirewallEnabled) {
parent: resHubVnet
name: 'AzureFirewallSubnet'
}
resource resAzureFirewallMgmtSubnetRef 'Microsoft.Network/virtualNetworks/subnets@2023-02-01' existing = if (parAzFirewallEnabled && (contains(map(parSubnets, subnets => subnets.name), 'AzureFirewallManagementSubnet'))) {
parent: resHubVnet
name: 'AzureFirewallManagementSubnet'
}
module modAzureFirewallPublicIp '../publicIp/publicIp.bicep' = if (parAzFirewallEnabled) {
name: 'deploy-Firewall-Public-IP'
params: {
parLocation: parLocation
parAvailabilityZones: parAzFirewallAvailabilityZones
parPublicIpName: '${parPublicIpPrefix}${parAzFirewallName}${parPublicIpSuffix}'
parPublicIpProperties: {
publicIpAddressVersion: 'IPv4'
publicIpAllocationMethod: 'Static'
}
parPublicIpSku: {
name: parPublicIpSku
}
parResourceLockConfig: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock : parAzureFirewallLock
parTags: parTags
parTelemetryOptOut: parTelemetryOptOut
}
}
module modAzureFirewallMgmtPublicIp '../publicIp/publicIp.bicep' = if (parAzFirewallEnabled && (contains(map(parSubnets, subnets => subnets.name), 'AzureFirewallManagementSubnet'))) {
name: 'deploy-Firewall-mgmt-Public-IP'
params: {
parLocation: parLocation
parAvailabilityZones: parAzFirewallAvailabilityZones
parPublicIpName: '${parPublicIpPrefix}${parAzFirewallName}-mgmt${parPublicIpSuffix}'
parPublicIpProperties: {
publicIpAddressVersion: 'IPv4'
publicIpAllocationMethod: 'Static'
}
parPublicIpSku: {
name: 'Standard'
}
parResourceLockConfig: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock : parAzureFirewallLock
parTags: parTags
parTelemetryOptOut: parTelemetryOptOut
}
}
resource resFirewallPolicies 'Microsoft.Network/firewallPolicies@2023-02-01' = if (parAzFirewallEnabled && parAzFirewallPoliciesEnabled) {
name: parAzFirewallPoliciesName
location: parLocation
tags: parTags
properties: (parAzFirewallTier == 'Basic') ? {
sku: {
tier: parAzFirewallTier
}
threatIntelMode: 'Alert'
} : {
dnsSettings: {
enableProxy: parAzFirewallDnsProxyEnabled
servers: parAzFirewallDnsServers
}
sku: {
tier: parAzFirewallTier
}
threatIntelMode: parAzFirewallIntelMode
}
}
// Create Azure Firewall Policy resource lock if parAzFirewallEnabled is true and parGlobalResourceLock.kind != 'None' or if parAzureFirewallLock.kind != 'None'
resource resFirewallPoliciesLock 'Microsoft.Authorization/locks@2020-05-01' = if (parAzFirewallEnabled && (parAzureFirewallLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resFirewallPolicies
name: parAzureFirewallLock.?name ?? '${resFirewallPolicies.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parAzureFirewallLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parAzureFirewallLock.?notes
}
}
// AzureFirewallSubnet is required to deploy Azure Firewall . This subnet must exist in the parsubnets array if you deploy.
// There is a minimum subnet requirement of /26 prefix.
resource resAzureFirewall 'Microsoft.Network/azureFirewalls@2023-02-01' = if (parAzFirewallEnabled) {
dependsOn: [
resGateway
]
name: parAzFirewallName
location: parLocation
tags: parTags
zones: (!empty(parAzFirewallAvailabilityZones) ? parAzFirewallAvailabilityZones : [])
properties: parAzFirewallTier == 'Basic' ? {
ipConfigurations: varAzFirewallUseCustomPublicIps
? map(parAzFirewallCustomPublicIps, ip =>
{
name: 'ipconfig${uniqueString(ip)}'
properties: ip == parAzFirewallCustomPublicIps[0]
? {
subnet: {
id: resAzureFirewallSubnetRef.id
}
publicIPAddress: {
id: parAzFirewallEnabled ? ip : ''
}
}
: {
publicIPAddress: {
id: parAzFirewallEnabled ? ip : ''
}
}
})
: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: resAzureFirewallSubnetRef.id
}
publicIPAddress: {
id: parAzFirewallEnabled ? modAzureFirewallPublicIp.outputs.outPublicIpId : ''
}
}
}
]
managementIpConfiguration: {
name: 'mgmtIpConfig'
properties: {
publicIPAddress: {
id: parAzFirewallEnabled ? modAzureFirewallMgmtPublicIp.outputs.outPublicIpId : ''
}
subnet: {
id: resAzureFirewallMgmtSubnetRef.id
}
}
}
sku: {
name: 'AZFW_VNet'
tier: parAzFirewallTier
}
firewallPolicy: {
id: resFirewallPolicies.id
}
} : {
ipConfigurations: varAzFirewallUseCustomPublicIps
? map(parAzFirewallCustomPublicIps, ip =>
{
name: 'ipconfig${uniqueString(ip)}'
properties: ip == parAzFirewallCustomPublicIps[0]
? {
subnet: {
id: resAzureFirewallSubnetRef.id
}
publicIPAddress: {
id: parAzFirewallEnabled ? ip : ''
}
}
: {
publicIPAddress: {
id: parAzFirewallEnabled ? ip : ''
}
}
})
: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: resAzureFirewallSubnetRef.id
}
publicIPAddress: {
id: parAzFirewallEnabled ? modAzureFirewallPublicIp.outputs.outPublicIpId : ''
}
}
}
]
sku: {
name: 'AZFW_VNet'
tier: parAzFirewallTier
}
firewallPolicy: {
id: resFirewallPolicies.id
}
}
}
// Create Azure Firewall resource lock if parAzFirewallEnabled is true and parGlobalResourceLock.kind != 'None' or if parAzureFirewallLock.kind != 'None'
resource resAzureFirewallLock 'Microsoft.Authorization/locks@2020-05-01' = if (parAzFirewallEnabled && (parAzureFirewallLock.kind != 'None' || parGlobalResourceLock.kind != 'None')) {
scope: resAzureFirewall
name: parAzureFirewallLock.?name ?? '${resAzureFirewall.name}-lock'
properties: {
level: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.kind : parAzureFirewallLock.kind
notes: (parGlobalResourceLock.kind != 'None') ? parGlobalResourceLock.?notes : parAzureFirewallLock.?notes
}