-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.bicep
More file actions
311 lines (276 loc) · 8.83 KB
/
main.bicep
File metadata and controls
311 lines (276 loc) · 8.83 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
306
307
308
309
310
311
@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('Specifies the location for all resources.')
param location string = resourceGroup().location
@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 = 'Standard'
@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 = 'S1'
@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 hosting plan.')
@allowed([
'app' // Windows Web app
'app,linux' // Linux Web app
'app,linux,container' // Linux Container Web app
'hyperV' // Windows Container Web App
'app,container,windows' // Windows Container Web App
'app,linux,kubernetes' // Linux Web App on ARC
'app,linux,container,kubernetes' // Linux Container Web App on ARC
'functionapp' // Function Code App
'functionapp,linux' // Linux Consumption 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 the public network access is enabled or disabled')
@allowed([
'Enabled'
'Disabled'
])
param publicNetworkAccess string = 'Enabled'
@description('Specifies whether Always On is enabled for the Azure Functions App.')
param alwaysOn bool = true
@description('Specifies the optional Git Repo URL.')
param repoUrl string = ''
@description('Specifies the tags to be applied to the resources.')
param tags object = {
environment: 'test'
iac: 'bicep'
}
@description('Specifies the sku of the Azure Storage account.')
param storageAccountSku string = 'Standard_LRS'
@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 type of managed identity.')
@allowed([
'SystemAssigned'
'UserAssigned'
])
param managedIdentityType string = 'SystemAssigned'
var functionAppName = '${prefix}-functionapp-${suffix}'
var appServicePlanName = '${prefix}-app-service-plan-${suffix}'
var storageAccountName = '${prefix}storage${suffix}'
var managedIdentityName = '${prefix}-identity-${suffix}'
var storageAccountConnectionString = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = if (managedIdentityType == 'UserAssigned') {
name: managedIdentityName
location: location
tags: tags
}
resource storageBlobDataContributorRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
scope: subscription()
}
resource storageQueueDataContributorRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: '974c5e8b-45b9-4653-ba55-5f855dd0fb88'
scope: subscription()
}
resource storageBlobDataContributorRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(storageAccount.id, functionApp.id, storageBlobDataContributorRoleDefinition.id)
scope: storageAccount
properties: {
roleDefinitionId: storageBlobDataContributorRoleDefinition.id
principalId: managedIdentityType == 'SystemAssigned' ? functionApp.identity.principalId : managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
}
resource storageQueueDataContributorRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(storageAccount.id, functionApp.id, storageQueueDataContributorRoleDefinition.id)
scope: storageAccount
properties: {
roleDefinitionId: storageQueueDataContributorRoleDefinition.id
principalId: managedIdentityType == 'SystemAssigned' ? functionApp.identity.principalId : managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-01-01' = {
name: storageAccountName
location: location
tags: tags
sku: {
name: storageAccountSku
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2025-01-01' = {
parent: storageAccount
name: 'default'
}
resource inputContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' = {
parent: blobServices
name: inputContainerName
}
resource outputContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' = {
parent: blobServices
name: outputContainerName
}
resource appServicePlan 'Microsoft.Web/serverfarms@2024-11-01' = {
name: appServicePlanName
location: location
tags: tags
kind: appServicePlanKind
sku: {
tier: skuTier
name: skuName
}
properties: {
reserved: reserved
zoneRedundant: zoneRedundant
maximumElasticWorkerCount: skuTier == 'FlexConsumption' ? 1 : 20
}
}
resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
name: functionAppName
location: location
tags: tags
kind: functionAppKind
properties: {
httpsOnly: httpsOnly
reserved: true
serverFarmId: appServicePlan.id
virtualNetworkSubnetId: null
siteConfig: {
alwaysOn: alwaysOn
linuxFxVersion: toUpper('${runtimeName}|${runtimeVersion}')
minTlsVersion: minTlsVersion
ftpsState: 'FtpsOnly'
publicNetworkAccess: publicNetworkAccess
}
}
identity: {
type: managedIdentityType
userAssignedIdentities : managedIdentityType == 'SystemAssigned' ? null : {
'${managedIdentity.id}': {}
}
}
}
resource configAppSettings 'Microsoft.Web/sites/config@2024-11-01' = {
parent: functionApp
name: 'appsettings'
properties: {
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
ENABLE_ORYX_BUILD: 'true'
AzureWebJobsStorage: storageAccountConnectionString
FUNCTIONS_WORKER_RUNTIME: runtimeName
FUNCTIONS_EXTENSION_VERSION: '~4'
STORAGE_ACCOUNT_CONNECTION_STRING__blobServiceUri: storageAccount.properties.primaryEndpoints.blob
STORAGE_ACCOUNT_CONNECTION_STRING__queueServiceUri: storageAccount.properties.primaryEndpoints.queue
STORAGE_ACCOUNT_CONNECTION_STRING__tableServiceUri: storageAccount.properties.primaryEndpoints.table
INPUT_STORAGE_CONTAINER_NAME: inputContainer.name
OUTPUT_STORAGE_CONTAINER_NAME: outputContainer.name
AZURE_CLIENT_ID: managedIdentityType == 'SystemAssigned' ? '' : managedIdentity.properties.clientId
}
dependsOn: [
storageBlobDataContributorRoleAssignment
]
}
resource functionAppSourceControl 'Microsoft.Web/sites/sourcecontrols@2024-11-01' = if (contains(repoUrl,'http')){
name: 'web'
parent: functionApp
properties: {
repoUrl: repoUrl
branch: 'master'
isManualIntegration: true
}
}
output appServicePlanName string = appServicePlan.name
output functionAppName string = functionApp.name
output functionAppUrl string = functionApp.properties.defaultHostName
output storageAccountName string = storageAccountName