-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork.bicep
277 lines (235 loc) · 8.26 KB
/
network.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
import * as _networkType from 'private/types/network.bicep'
import * as _networkVar from 'private/variables/network.bicep'
import * as _networkFunction from 'private/functions/network.bicep'
import * as _resourceType from 'private/types/resource.bicep'
import * as _resourceFunction from 'private/functions/resource.bicep'
import * as _locationType from 'private/types/location.bicep'
/* ----------------------------------------
🤠 Bicep# - Public variables 🤠
------------------------------------------- */
@description('''
Private endpoint group Ids, also known as sub-resources.
Please look at https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource for a detailed reference.
''')
@export()
var groupIds = _networkVar.groupIds
@description('''
NSG Rule direction
''')
@export()
var nsgRuleDirections = _networkVar.nsgRuleDirections
@description('''
NSG Rule access
''')
@export()
var nsgRuleAccesses = _networkVar.nsgRuleAccesses
@description('''
NSG Rule Service tags for inbound.
Please look at https://learn.microsoft.com/en-us/azure/virtual-network/service-tags-overview for a detailed reference.
''')
@export()
var nsgRuleServiceTagsInbound = _networkVar.nsgRuleServiceTagsInbound
@description('''
NSG Rule Service tags for outbound.
Please look at https://learn.microsoft.com/en-us/azure/virtual-network/service-tags-overview for a detailed reference.
''')
@export()
var nsgRuleServiceTagsOutbound = _networkVar.nsgRuleServiceTagsOutbound
@description('''
NSG Rule Service tags that are regional.
Please note, this list is generated during compile-time for Bicep# with a specific location.
Please look at https://learn.microsoft.com/en-us/azure/virtual-network/service-tags-overview for a detailed reference.
''')
@export()
var nsgRuleServiceTagsRegional = _networkVar.nsgRuleServiceTagsRegional
@description('''
NSG Rule Destionation Service. The service specifies the destination protocol and port range for this rule.
You can choose a predefined service, like RDP or SSH, or provide a custom port range.
''')
@export()
var nsgRuleDestinationServices = _networkVar.nsgRuleDestinationServices
@description('''
Private Endpoint connection names from own and other tenants with either manual or auto-approval. Name pattern is:
- `[private endpoint name]` for a private endpoint resource in own tenant.
- `[resourceName]_[private endpoint name]` for other (managed) private endpoint connections.
''')
@export()
var privateEndpointConnectionNames = _networkVar.privateEndpointConnectionNames
@description('''
Lookup array to check if the connection is still pending.
Some private endpoint connections do not like to be approved twice. This depends on the parent resource type.
''')
@export()
var privateEndpointConnectionNamesPendingLookup = _networkVar.privateEndpointConnectionNamesPendingLookup
/* ----------------------------------------
😎 Bicep# - Public types 😎
------------------------------------------- */
@export()
type nsgName = _networkType.nsgName
@export()
type nsgProperties = _networkType.nsgProperties
@export()
type nsgRulePropertiesOptionalPriority = _networkType.nsgRulePropertiesOptionalPriority
@export()
type buildNsgRuleServiceTagFirewallnsgRuleProperties = _networkType.buildNsgRuleServiceTagFirewallnsgRuleProperties
@export()
type peName = _networkType.peName
@export()
type peProperties = _networkType.peProperties
type subnet = _networkType.subnet
@export()
type vnetProperties = _networkType.vnetProperties
@description('''
NSG Rule Service tags that support regional scope.
''')
@export()
type serviceTagRegional = _networkType.serviceTagRegional
@description('''
NSG Rule Service tags that support firewall use.
''')
@export()
type serviceTagFirewallUse = _networkType.serviceTagFirewallUse
@description('''
NSG Rule Service tags that not support firewall use.
''')
@export()
type serviceTagFirewallAndNonFirewallUse = _networkType.serviceTagFirewallAndNonFirewallUse
@description('''
NSG Rule direction.
''')
@export()
type nsgRuleDirection = _networkType.nsgRuleDirection
@description('''
NSG Rule access.
''')
@export()
type nsgRuleAccess = _networkType.nsgRuleAccess
@export()
type nsgRuleDestinationService = _networkType.nsgRuleDestinationService
/* ----------------------------------------
💪 Bicep# - Public functions 💪
------------------------------------------- */
@description('''
Build a vnet.
''')
@export()
func buildVnet(
vnetPostfix string,
addressPrefixes array,
enableDdosProtection bool,
virtualNetworkPeerings array?,
subnets array
) _resourceType.resourceFormat => {
name: 'vnet-${vnetPostfix}'
properties: _networkFunction.buildVnetProperties(
addressPrefixes,
enableDdosProtection,
virtualNetworkPeerings,
subnets
)
}
@description('''
Build a subnet.
''')
@export()
func buildSubnet(
subnetPostfix string,
subnetAddressPrefix string,
networkSecurityGroupId string,
serviceEndpoints array?
) _resourceType.resourceFormat => {
name: 'snet-${subnetPostfix}'
properties: _networkFunction.buildSubnetProperties(subnetAddressPrefix, networkSecurityGroupId, serviceEndpoints)
}
@description('''
Build a private endpoint.
''')
@export()
func buildPrivateEndpoint(targetResourceName string, targetResourceId string, groupId string, subnetId string) _resourceType.resourceFormat => {
name: 'pe-${targetResourceName}-${groupId}'
properties: _networkFunction.buildPrivateEndpointProperties(targetResourceName, targetResourceId, groupId, subnetId)
}
@description('''
Build a private endpoint connection approval.
''')
@export()
func buildPrivateEndpointConnectionApproval(connectionName string, additionalInfo string) _resourceType.resourceFormat => {
name: connectionName
properties: _networkFunction.buildPrivateEndpointConnectionApprovalProperties(connectionName, additionalInfo)
}
@description('''
Build an NSG.
''')
@export()
func buildNsg(subnetPostfix string, securityRules nsgProperties.securityRules) _resourceType.resourceFormat => {
name: 'nsg-${subnetPostfix}'
properties: _networkFunction.buildNsgProperties(securityRules)
}
@description('''
Build an NSG rule from IP to IP.
''')
@export()
func buildNsgRuleIpToIp(
direction nsgRuleDirection,
access nsgRuleAccess,
sourceAddressPrefix string,
destinationAddressPrefix string,
destinationService nsgRuleDestinationService
) _resourceType.resourceFormat => {
name: _networkFunction.buildNsgRuleName(access, sourceAddressPrefix, destinationAddressPrefix, direction)
properties: _networkFunction.buildNsgRuleProperties(
direction,
access,
sourceAddressPrefix,
destinationAddressPrefix,
destinationService
)
}
@description('''
Build an NSG rule with service tags that are supported on Azure Firewall.
''')
@export()
func buildNsgRuleFirewallServiceTagToServiceTag(
direction nsgRuleDirection,
access nsgRuleAccess,
sourceServiceTag serviceTagFirewallUse,
destinationServiceTag serviceTagFirewallUse,
destinationService nsgRuleDestinationService
) _resourceType.resourceFormat => {
name: _networkFunction.buildNsgRuleName(access, sourceServiceTag, destinationServiceTag, direction)
properties: _networkFunction.buildNsgRuleProperties(
direction,
access,
sourceServiceTag,
destinationServiceTag,
destinationService
)
}
@description('''
Build an NSG rule with service tags.
''')
@export()
func buildNsgRuleServiceTagToServiceTag(
direction nsgRuleDirection,
access nsgRuleAccess,
sourceServiceTag serviceTagFirewallAndNonFirewallUse,
destinationServiceTag serviceTagFirewallAndNonFirewallUse,
destinationService nsgRuleDestinationService
) _resourceType.resourceFormat => {
name: _networkFunction.buildNsgRuleName(access, sourceServiceTag, destinationServiceTag, direction)
properties: _networkFunction.buildNsgRuleProperties(
direction,
access,
sourceServiceTag,
destinationServiceTag,
destinationService
)
}
@description('''
Create an NSG rule collection and add the 'priority' element based on the order of the nsgRuleResourceCollectionUnPrioritized. Starts at 100.
''')
@export()
func createNsgRuleCollectionWithPriority(
nsgRuleResourceCollectionUnPrioritized _networkType.nsgProperties.securityRules
) _networkType.nsgProperties.securityRules =>
_resourceFunction.makeIteratedResourceCollection(nsgRuleResourceCollectionUnPrioritized, 'priority', 100)