-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.bicep
More file actions
272 lines (247 loc) · 6.69 KB
/
Copy pathmain.bicep
File metadata and controls
272 lines (247 loc) · 6.69 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
param env string = 'Dev'
param existingAppClientObjectId string
// secrets
@secure()
param DataverseUrl string
// Naming (OBS: some resources have limitations to their naming)
var solutionId = 'templatesolutionname'
var companyId = 'templatecompanyid'
var namingSuffix = '${toLower(companyId)}-${toLower(solutionId)}-${toLower(env)}'
// Variables
var location = resourceGroup().location
resource logworkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: 'log-${namingSuffix}'
location: location
properties: {
retentionInDays: 30
sku: {
name: 'PerGB2018'
}
}
}
resource appinsights 'Microsoft.Insights/components@2020-02-02' = {
name: 'ai-${namingSuffix}'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logworkspace.id
Flow_Type: 'Redfield'
Request_Source: 'IbizaWebAppExtensionCreate'
RetentionInDays: 30
}
}
resource actionGroup 'Microsoft.Insights/actionGroups@2023-01-01' = {
name: 'ag-${namingSuffix}'
location: 'global'
properties: {
enabled: true
groupShortName: 'alertgrp'
emailReceivers: [
]
}
}
resource alertRule 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: 'alert-exception-${namingSuffix}'
location: 'global'
properties: {
description: 'Alert for exceptions in Function Apps'
severity: 2
enabled: true
scopes: [
appinsights.id
]
evaluationFrequency: 'PT30M'
windowSize: 'PT30M'
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
name: 'ExceptionCount'
metricName: 'exceptions/count'
timeAggregation: 'Count'
operator: 'GreaterThan'
threshold: 0
criterionType: 'StaticThresholdCriterion'
metricNamespace: 'microsoft.insights/components'
}
]
}
actions: [
{
actionGroupId: actionGroup.id
}
]
autoMitigate: false
targetResourceRegion: 'global'
targetResourceType: 'microsoft.insights/components'
}
}
module appPlan 'modules/AppServicePlan.bicep' = {
name: 'appplan'
params: {
skuName: 'B1'
location: location
name: 'asp-${namingSuffix}'
}
}
resource vnet 'Microsoft.Network/virtualNetworks@2020-07-01' = {
name: 'ipvnet-${namingSuffix}'
location: location
properties: {
addressSpace: {
addressPrefixes: [
'172.24.0.0/24'
]
}
subnets: [
{
name: 'ipsubnet-${namingSuffix}'
properties: {
addressPrefix: '172.24.0.0/27'
natGateway: {
id: natGateway.id
}
}
}
]
}
}
resource natGateway 'Microsoft.Network/natGateways@2020-07-01' = {
name: 'ipnat-${namingSuffix}'
location: location
sku: {
name: 'Standard'
}
properties: {
idleTimeoutInMinutes: 4
publicIpAddresses: [
{
id: publicIp.id
}
]
}
}
resource publicIp 'Microsoft.Network/publicIPAddresses@2020-07-01' = {
name: 'ip-${namingSuffix}'
location: location
sku: {
name: 'Standard'
tier: 'Regional'
}
properties: {
publicIPAllocationMethod: 'Static'
publicIPAddressVersion: 'IPv4'
}
}
module userManangedIdentityModule 'modules/UserManagedIdentity.bicep' = {
name: 'userManangedIdentityModule'
params: {
name: 'mi-${namingSuffix}'
location: location
}
}
module principals 'principals.bicep' = {
name: 'principal'
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: 'sa${padLeft(replace(namingSuffix, '-', ''), 3, 'x')}'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
properties: {
allowBlobPublicAccess: true
isHnsEnabled: true
accessTier: 'Cool'
}
}
var storageQueueContributorRoleId = '974c5e8b-45b9-4653-ba55-5f855dd0fb88'
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: storageAccount
name: guid(storageAccount.id, existingAppClientObjectId, storageQueueContributorRoleId)
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', storageQueueContributorRoleId)
principalId: existingAppClientObjectId
principalType: 'ServicePrincipal'
}
}
resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = {
name: 'asp-${namingSuffix}'
location: location
sku: {
name: 'S1'
}
kind: 'app'
properties: {
reserved: false
}
}
var kvPrincipals = concat(principals.outputs.userprincipals, [
userManangedIdentityModule.outputs.userManIdentityPrincipalId
])
var keyvaultName = 'kv-${namingSuffix}'
module keyvault 'modules/keyVault.bicep' = {
name: 'keyvault'
params: {
name: keyvaultName
location: location
principalIds: kvPrincipals
}
}
var dataverseSecrets = [
]
module kvSecrets 'modules/keyVaultSecrets.bicep' = {
name: 'keyVaultSecrets'
params: {
keyVaultName: keyvault.outputs.keyvaultname
secrets: concat(dataverseSecrets, [
{ name: 'StorageAccountName', value: storageAccount.name }
])
}
}
var functionApps = [
{
functionAppName: 'func-economyarea-${namingSuffix}'
kvSecrets: dataverseSecrets
funcAppSettings: []
functionAppVersion: null
staticIp: false
externalPackageUrl: null
isolated: true
}
]
module functionApp 'modules/functionApps.bicep' = [for app in functionApps: {
name: app.functionAppName
params: {
location: location
managedIdentityId: userManangedIdentityModule.outputs.userManIdentityId
storageAccountConnectionString: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=core.windows.net'
functionAppName: app.functionAppName
functionAppVersion: app.functionAppVersion
InstrumentationKey: appinsights.properties.InstrumentationKey
appInsightsConnectionString: appinsights.properties.ConnectionString
appSettings: app.funcAppSettings
keyVaultReferenceIdentity: userManangedIdentityModule.outputs.userManIdentityPrincipalId
managedIdentityClientId: userManangedIdentityModule.outputs.userManIdentityClientId
dataverseUrl: DataverseUrl
planId: appPlan.outputs.id
kvSecrets: app.kvSecrets
kvName: keyvault.outputs.keyvaultname
subnetId: app.staticIp ? vnet.properties.subnets[0].id : null
packageUri: app.externalPackageUrl
workerRuntime: app.isolated ? 'dotnet-isolated' : 'dotnet'
netFrameworkVersion: app.isolated ? 'v8.0' : 'v6.0'
}
}]
var storageQueues = [
'createinvoicesqueue'
]
module storagequeue 'modules/StorageQueue.bicep' = [for queue in storageQueues: {
name: queue
params: {
storageaccountname: storageAccount.name
storageaccountqueuename: queue
}
}]