forked from Azure-Samples/function-app-arm-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.bicep
454 lines (417 loc) · 12.6 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
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
@description('The name of the Azure Function app.')
param functionAppName string = 'func-${uniqueString(resourceGroup().id)}'
@description('The location into which the resources should be deployed.')
param location string = resourceGroup().location
@description('The language worker runtime to load in the function app.')
@allowed([
'dotnet'
'node'
'python'
'java'
])
param functionWorkerRuntime string = 'node'
@description('Specifies the OS used for the Azure Function hosting plan.')
@allowed([
'Windows'
'Linux'
])
param functionPlanOS string = 'Windows'
@description('Specifies the Azure Function hosting plan SKU.')
@allowed([
'EP1'
'EP2'
'EP3'
])
param functionAppPlanSku string = 'EP1'
@description('The name of the Azure Function hosting plan.')
param functionAppPlanName string = 'plan-${uniqueString(resourceGroup().id)}'
@description('The name of the backend Azure storage account used by the Azure Function app.')
param functionStorageAccountName string = 'st${uniqueString(resourceGroup().id)}'
@description('The name of the virtual network for virtual network integration.')
param vnetName string = 'vnet-${uniqueString(resourceGroup().id)}'
@description('The name of the virtual network subnet to be associated with the Azure Function app.')
param functionSubnetName string = 'snet-func'
@description('The name of the virtual network subnet used for allocating IP addresses for private endpoints.')
param privateEndpointSubnetName string = 'snet-pe'
@description('The IP adddress space used for the virtual network.')
param vnetAddressPrefix string = '10.100.0.0/16'
@description('The IP address space used for the Azure Function integration subnet.')
param functionSubnetAddressPrefix string = '10.100.0.0/24'
@description('The IP address space used for the private endpoints.')
param privateEndpointSubnetAddressPrefix string = '10.100.1.0/24'
@description('Only required for Linux app to represent runtime stack in the format of \'runtime|runtimeVersion\'. For example: \'python|3.9\'')
param linuxFxVersion string = ''
var applicationInsightsName = 'appi-${uniqueString(resourceGroup().id)}'
var privateStorageFileDnsZoneName = 'privatelink.file.${environment().suffixes.storage}'
var privateEndpointStorageFileName = '${functionStorageAccountName}-file-private-endpoint'
var privateStorageTableDnsZoneName = 'privatelink.table.${environment().suffixes.storage}'
var privateEndpointStorageTableName = '${functionStorageAccountName}-table-private-endpoint'
var privateStorageBlobDnsZoneName = 'privatelink.blob.${environment().suffixes.storage}'
var privateEndpointStorageBlobName = '${functionStorageAccountName}-blob-private-endpoint'
var privateStorageQueueDnsZoneName = 'privatelink.queue.${environment().suffixes.storage}'
var privateEndpointStorageQueueName = '${functionStorageAccountName}-queue-private-endpoint'
var functionContentShareName = 'function-content-share'
var isReserved = ((functionPlanOS == 'Linux') ? true : false)
resource vnet 'Microsoft.Network/virtualNetworks@2022-05-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vnetAddressPrefix
]
}
subnets: [
{
name: functionSubnetName
properties: {
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
delegations: [
{
name: 'webapp'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
}
]
addressPrefix: functionSubnetAddressPrefix
}
}
{
name: privateEndpointSubnetName
properties: {
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
addressPrefix: privateEndpointSubnetAddressPrefix
}
}
]
}
}
resource privateStorageFileDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: privateStorageFileDnsZoneName
location: 'global'
}
resource privateStorageBlobDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: privateStorageBlobDnsZoneName
location: 'global'
}
resource privateStorageQueueDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: privateStorageQueueDnsZoneName
location: 'global'
}
resource privateStorageTableDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: privateStorageTableDnsZoneName
location: 'global'
}
resource privateStorageFileDnsZoneLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
parent: privateStorageFileDnsZone
name: '${privateStorageFileDnsZoneName}-link'
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnet.id
}
}
}
resource privateStorageBlobDnsZoneLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
parent: privateStorageBlobDnsZone
name: '${privateStorageBlobDnsZoneName}-link'
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnet.id
}
}
}
resource privateStorageTableDnsZoneLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
parent: privateStorageTableDnsZone
name: '${privateStorageTableDnsZoneName}-link'
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnet.id
}
}
}
resource privateStorageQueueDnsZoneLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
parent: privateStorageQueueDnsZone
name: '${privateStorageQueueDnsZoneName}-link'
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnet.id
}
}
}
resource privateEndpointStorageFilePrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2022-05-01' = {
parent: privateEndpointStorageFile
name: 'filePrivateDnsZoneGroup'
properties: {
privateDnsZoneConfigs: [
{
name: 'config'
properties: {
privateDnsZoneId: privateStorageFileDnsZone.id
}
}
]
}
}
resource privateEndpointStorageBlobPrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2022-05-01' = {
parent: privateEndpointStorageBlob
name: 'blobPrivateDnsZoneGroup'
properties: {
privateDnsZoneConfigs: [
{
name: 'config'
properties: {
privateDnsZoneId: privateStorageBlobDnsZone.id
}
}
]
}
}
resource privateEndpointStorageTablePrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2022-05-01' = {
parent: privateEndpointStorageTable
name: 'tablePrivateDnsZoneGroup'
properties: {
privateDnsZoneConfigs: [
{
name: 'config'
properties: {
privateDnsZoneId: privateStorageTableDnsZone.id
}
}
]
}
}
resource privateEndpointStorageQueuePrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2022-05-01' = {
parent: privateEndpointStorageQueue
name: 'queuePrivateDnsZoneGroup'
properties: {
privateDnsZoneConfigs: [
{
name: 'config'
properties: {
privateDnsZoneId: privateStorageQueueDnsZone.id
}
}
]
}
}
resource privateEndpointStorageFile 'Microsoft.Network/privateEndpoints@2022-05-01' = {
name: privateEndpointStorageFileName
location: location
properties: {
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, privateEndpointSubnetName)
}
privateLinkServiceConnections: [
{
name: 'MyStorageFilePrivateLinkConnection'
properties: {
privateLinkServiceId: functionStorageAccount.id
groupIds: [
'file'
]
}
}
]
}
dependsOn: [
vnet
]
}
resource privateEndpointStorageBlob 'Microsoft.Network/privateEndpoints@2022-05-01' = {
name: privateEndpointStorageBlobName
location: location
properties: {
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, privateEndpointSubnetName)
}
privateLinkServiceConnections: [
{
name: 'MyStorageBlobPrivateLinkConnection'
properties: {
privateLinkServiceId: functionStorageAccount.id
groupIds: [
'blob'
]
}
}
]
}
dependsOn: [
vnet
]
}
resource privateEndpointStorageTable 'Microsoft.Network/privateEndpoints@2022-05-01' = {
name: privateEndpointStorageTableName
location: location
properties: {
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, privateEndpointSubnetName)
}
privateLinkServiceConnections: [
{
name: 'MyStorageTablePrivateLinkConnection'
properties: {
privateLinkServiceId: functionStorageAccount.id
groupIds: [
'table'
]
}
}
]
}
dependsOn: [
vnet
]
}
resource privateEndpointStorageQueue 'Microsoft.Network/privateEndpoints@2022-05-01' = {
name: privateEndpointStorageQueueName
location: location
properties: {
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, privateEndpointSubnetName)
}
privateLinkServiceConnections: [
{
name: 'MyStorageQueuePrivateLinkConnection'
properties: {
privateLinkServiceId: functionStorageAccount.id
groupIds: [
'queue'
]
}
}
]
}
dependsOn: [
vnet
]
}
resource functionStorageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
name: functionStorageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
properties: {
publicNetworkAccess: 'Disabled'
allowBlobPublicAccess: false
networkAcls: {
bypass: 'None'
defaultAction: 'Deny'
}
}
}
resource share 'Microsoft.Storage/storageAccounts/fileServices/shares@2022-05-01' = {
name: '${functionStorageAccountName}/default/${functionContentShareName}'
dependsOn: [
functionStorageAccount
]
}
resource applicationInsight 'Microsoft.Insights/components@2020-02-02' = {
name: applicationInsightsName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
resource functionAppPlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: functionAppPlanName
location: location
sku: {
tier: 'ElasticPremium'
name: functionAppPlanSku
size: functionAppPlanSku
family: 'EP'
}
kind: 'elastic'
properties: {
maximumElasticWorkerCount: 20
reserved: isReserved
}
}
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
name: functionAppName
location: location
kind: (isReserved ? 'functionapp,linux' : 'functionapp')
properties: {
reserved: isReserved
serverFarmId: functionAppPlan.id
siteConfig: {
functionsRuntimeScaleMonitoringEnabled: true
linuxFxVersion: (isReserved ? linuxFxVersion : json('null'))
appSettings: [
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: applicationInsight.properties.InstrumentationKey
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${functionStorageAccountName};AccountKey=${functionStorageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${functionStorageAccountName};AccountKey=${functionStorageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTSHARE'
value: functionContentShareName
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: functionWorkerRuntime
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '~14'
}
{
name: 'WEBSITE_VNET_ROUTE_ALL'
value: '1'
}
{
name: 'WEBSITE_CONTENTOVERVNET'
value: '1'
}
]
}
}
dependsOn: [
share
privateStorageFileDnsZoneLink
privateEndpointStorageFilePrivateDnsZoneGroup
privateStorageBlobDnsZoneLink
privateEndpointStorageBlobPrivateDnsZoneGroup
privateStorageTableDnsZoneLink
privateEndpointStorageTablePrivateDnsZoneGroup
privateStorageQueueDnsZoneLink
privateEndpointStorageQueuePrivateDnsZoneGroup
]
}
resource networkConfig 'Microsoft.Web/sites/networkConfig@2022-03-01' = {
parent: functionApp
name: 'virtualNetwork'
properties: {
subnetResourceId: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, functionSubnetName)
swiftSupported: true
}
dependsOn: [
vnet
]
}