Repository navigation
Expand file tree
/
Copy pathmain.bicep
More file actions
305 lines (269 loc) · 8.7 KB
/
Copy pathmain.bicep
File metadata and controls
305 lines (269 loc) · 8.7 KB
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
@description('Specifies the prefix for the name of the Azure resources.')
@minLength(2)
param prefix string = take(uniqueString(resourceGroup().id), 4)
@description('Specifies the suffix for the name of the Azure resources.')
@minLength(2)
param suffix string = take(uniqueString(resourceGroup().id), 4)
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Specifies the sku of the Azure Storage account.')
param storageAccountSku string = 'Standard_LRS'
@description('Specifies the tier name for the hosting plan.')
@allowed([
'Basic'
'Standard'
'ElasticPremium'
'Premium'
'PremiumV2'
'Premium0V3'
'PremiumV3'
'PremiumMV3'
'Isolated'
'IsolatedV2'
'WorkflowStandard'
'FlexConsumption'
])
param skuTier string = 'Basic'
@description('Specifies the SKU name for the hosting plan.')
@allowed([
'B1'
'B2'
'B3'
'S1'
'S2'
'S3'
'EP1'
'EP2'
'EP3'
'P1'
'P2'
'P3'
'P1V2'
'P2V2'
'P3V2'
'P0V3'
'P1V3'
'P2V3'
'P3V3'
'P1MV3'
'P2MV3'
'P3MV3'
'P4MV3'
'P5MV3'
'I1'
'I2'
'I3'
'I1V2'
'I2V2'
'I3V2'
'I4V2'
'I5V2'
'I6V2'
'WS1'
'WS2'
'WS3'
'FC1'
])
param skuName string = 'B1'
@description('Specifies the kind of the hosting plan.')
@allowed([
'app'
'elastic'
'functionapp'
'windows'
'linux'
])
param appServicePlanKind string = 'linux'
@description('Specifies whether the hosting plan is reserved.')
param reserved bool = true
@description('Specifies whether the hosting plan is zone redundant.')
param zoneRedundant bool = false
@description('Specifies the language runtime used by the Azure Functions App.')
@allowed([
'dotnet'
'dotnet-isolated'
'python'
'java'
'node'
'powerShell'
'custom'
])
param runtimeName string
@description('Specifies the target language version used by the Azure Functions App.')
param runtimeVersion string
@description('Specifies the kind of the Azure Function App.')
@allowed([
'functionapp' // Function Code App
'functionapp,linux' // Linux Function App
'functionapp,linux,container,kubernetes' // Function Container App on ARC
'functionapp,linux,kubernetes' // Function Code App on ARC
])
param functionAppKind string = 'functionapp,linux'
@description('Specifies whether HTTPS is enforced for the Azure Functions App.')
param httpsOnly bool = false
@description('Specifies the minimum TLS version for the Azure Functions App.')
@allowed([
'1.0'
'1.1'
'1.2'
'1.3'
])
param minTlsVersion string = '1.2'
@description('Specifies whether Always On is enabled for the Azure Functions App: on an App Service plan, the Functions runtime goes idle after a few minutes of inactivity, and only HTTP requests wake it up.')
param alwaysOn bool = true
@description('Specifies whether the public network access is enabled or disabled')
@allowed([
'Enabled'
'Disabled'
])
param publicNetworkAccess string = 'Enabled'
@description('Optional Git Repo URL')
param repoUrl string = ' '
@description('Specifies the name of the input container.')
param inputContainerName string = 'input'
@description('Specifies the name of the output container.')
param outputContainerName string = 'output'
@description('Specifies the name of the input queue.')
param inputQueueName string = 'input'
@description('Specifies the name of the output queue.')
param outputQueueName string = 'output'
@description('Specifies the name of the trigger queue.')
param triggerQueueName string = 'trigger'
@description('Specifies the name of the input table.')
param inputTableName string = 'scoreboards'
@description('Specifies the name of the output table.')
param outputTableName string = 'winners'
@description('Specifies the comma-separated list of player names.')
param playerNames string = 'Alice,Anastasia,Paolo,Leo,Mia'
@description('Specifies the timer schedule for the timer triggered function.')
param timerSchedule string = '0 */1 * * * *'
@description('Specifies the tags to be applied to the resources.')
param tags object = {
environment: 'test'
iac: 'bicep'
}
@description('Specifies the name of the diagnostic settings of the function app and of the App Service plan.')
param diagnosticSettingsName string = 'default'
@description('Specifies the log categories that the diagnostic settings of the function app send to the Log Analytics workspace.')
param logCategories array = [
'FunctionAppLogs'
]
@description('Specifies the metric categories that the diagnostic settings of the function app and of the App Service plan send to the Log Analytics workspace.')
param metricCategories array = [
'AllMetrics'
]
//********************************************
// Variables
//********************************************
var functionAppName = '${prefix}-functionapp-${suffix}'
var appServicePlanName = '${prefix}-app-service-plan-${suffix}'
var storageAccountName = '${prefix}storage${suffix}'
var logAnalyticsName = '${prefix}-log-analytics-${suffix}'
var applicationInsightsName = '${prefix}-insights-${suffix}'
//********************************************
// Modules
//********************************************
module workspace 'modules/log-analytics.bicep' = {
name: 'workspace'
params: {
name: logAnalyticsName
location: location
tags: tags
}
}
module applicationInsights 'modules/application-insights.bicep' = {
name: 'applicationInsights'
params: {
name: applicationInsightsName
location: location
workspaceId: workspace.outputs.id
tags: tags
}
}
// The functions use the blobs, the queues and the tables of the storage account, where the Functions host also keeps
// its own data (AzureWebJobsStorage), so the three services have diagnostic settings. The functions create their
// containers, queues and tables themselves when they start.
module storageAccount 'modules/storage-account.bicep' = {
name: 'storageAccount'
params: {
name: storageAccountName
location: location
skuName: storageAccountSku
diagnosticServices: [
'blob'
'queue'
'table'
]
diagnosticSettingsName: diagnosticSettingsName
workspaceId: workspace.outputs.id
tags: tags
}
}
module appServicePlan 'modules/app-service-plan.bicep' = {
name: 'appServicePlan'
params: {
name: appServicePlanName
location: location
skuTier: skuTier
skuName: skuName
kind: appServicePlanKind
reserved: reserved
zoneRedundant: zoneRedundant
maximumElasticWorkerCount: skuTier == 'FlexConsumption' ? 1 : 20
diagnosticSettingsName: diagnosticSettingsName
metricCategories: metricCategories
workspaceId: workspace.outputs.id
tags: tags
}
}
module functionApp 'modules/function-app.bicep' = {
name: 'functionApp'
params: {
name: functionAppName
location: location
kind: functionAppKind
runtimeName: runtimeName
runtimeVersion: runtimeVersion
httpsOnly: httpsOnly
alwaysOn: alwaysOn
minTlsVersion: minTlsVersion
publicNetworkAccess: publicNetworkAccess
hostingPlanName: appServicePlan.outputs.name
storageAccountName: storageAccount.outputs.name
// The bindings of the functions connect to the storage account with the connection string of this setting
storageConnectionStringSettingName: 'STORAGE_ACCOUNT_CONNECTION_STRING'
appSettings: {
// The remote build installs requirements.txt
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
ENABLE_ORYX_BUILD: 'true'
// With telemetryMode set to OpenTelemetry in host.json, the Python worker sends the records of the function_app
// logger, the exceptions it logs, the custom events and the custom metric to Application Insights
PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY: 'true'
PYTHON_APPLICATIONINSIGHTS_LOGGER_NAME: 'function_app'
INPUT_STORAGE_CONTAINER_NAME: inputContainerName
OUTPUT_STORAGE_CONTAINER_NAME: outputContainerName
INPUT_QUEUE_NAME: inputQueueName
OUTPUT_QUEUE_NAME: outputQueueName
TRIGGER_QUEUE_NAME: triggerQueueName
INPUT_TABLE_NAME: inputTableName
OUTPUT_TABLE_NAME: outputTableName
PLAYER_NAMES: playerNames
TIMER_SCHEDULE: timerSchedule
APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.outputs.connectionString
}
repoUrl: repoUrl
repoBranch: 'main'
diagnosticSettingsName: diagnosticSettingsName
logCategories: logCategories
metricCategories: metricCategories
workspaceId: workspace.outputs.id
tags: tags
}
}
//********************************************
// Outputs
//********************************************
output functionAppName string = functionApp.outputs.name
output storageAccountName string = storageAccount.outputs.name
output logAnalyticsName string = workspace.outputs.name
output applicationInsightsName string = applicationInsights.outputs.name