Repository navigation
Expand file tree
/
Copy pathmain.bicep
More file actions
305 lines (267 loc) · 9.38 KB
/
Copy pathmain.bicep
File metadata and controls
305 lines (267 loc) · 9.38 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
//********************************************
// Parameters
//********************************************
@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 name of the image to be used for the Web App.')
param imageName string
@description('Specifies the tag of the image to be used for the Web App.')
param imageTag string
@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 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 webAppKind string = 'app,linux'
@description('Specifies whether HTTPS is enforced for the Azure Web App.')
param httpsOnly bool = false
@description('Specifies the minimum TLS version for the Azure Web App.')
@allowed([
'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 the optional Git Repo URL.')
param repoUrl string = ' '
@description('Specifies the name of the virtual network.')
param virtualNetworkName string = ''
@description('Specifies the address prefixes of the virtual network.')
param virtualNetworkAddressPrefixes string = '10.0.0.0/8'
@description('Specifies the name of the subnet used by the Web App for the regional virtual network integration.')
param webAppSubnetName string = 'app-subnet'
@description('Specifies the address prefix of the subnet used by the Web App for the regional virtual network integration.')
param webAppSubnetAddressPrefix string = '10.0.0.0/24'
@description('Specifies the name of the network security group associated to the subnet hosting the Web App.')
param webAppSubnetNsgName string = ''
@description('Specifies the name of the subnet which contains the private endpoint to the Azure CosmosDB for MongoDB API account.')
param peSubnetName string = 'pe-subnet'
@description('Specifies the address prefix of the subnet which contains the private endpoint to the Azure CosmosDB for MongoDB API account.')
param peSubnetAddressPrefix string = '10.0.1.0/24'
@description('Specifies the name of the network security group associated to the subnet hosting the private endpoint to the Azure CosmosDB for MongoDB API account.')
param peSubnetNsgName string = ''
@description('Specifies the length of the Public IP Prefix.')
@minValue(28)
@maxValue(32)
param natGatewayPublicIpPrefixLength int = 31
@description('Specifies the name of the Azure NAT Gateway.')
param natGatewayName string = ''
@description('Specifies a list of availability zones denoting the zone in which Nat Gateway should be deployed.')
param natGatewayZones array = []
@description('Specifies the idle timeout in minutes for the Azure NAT Gateway.')
param natGatewayIdleTimeoutMins int = 30
@description('Specifies the name of the Azure Container Registry resource.')
param acrName string = ''
@description('Specifies the name of the Azure Log Analytics resource.')
param logAnalyticsWorkspaceName string = ''
@description('Specifies the tags to be applied to the resources.')
param tags object = {
environment: 'test'
iac: 'bicep'
}
//********************************************
// Variables
//********************************************
var webAppName = '${prefix}-webapp-${suffix}'
var appServicePlanName = '${prefix}-app-service-plan-${suffix}'
var managedIdentityName = '${prefix}-identity-${suffix}'
var privateDnsZoneName = 'privatelink.azurecr.io'
var privateEndpointName = '${prefix}-acr-pe-${suffix}'
//********************************************
// Modules and Resources
//********************************************
resource workspace 'Microsoft.OperationalInsights/workspaces@2025-07-01' existing = {
name: logAnalyticsWorkspaceName == '' ? toLower('${prefix}-log-analytics-${suffix}') : logAnalyticsWorkspaceName
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2024-11-01-preview' existing = {
name: acrName == '' ? toLower('${prefix}acr${suffix}') : acrName
}
module managedIdentity 'modules/managed-identity.bicep' = {
name: 'managedIdentity'
params: {
// properties
name: managedIdentityName
containerRegistryName: containerRegistry.name
location: location
tags: tags
}
}
module network 'modules/virtual-network.bicep' = {
name: 'network'
params: {
virtualNetworkName: empty(virtualNetworkName) ? toLower('${prefix}-vnet-${suffix}') : virtualNetworkName
virtualNetworkAddressPrefixes: virtualNetworkAddressPrefixes
webAppSubnetName: webAppSubnetName
webAppSubnetAddressPrefix: webAppSubnetAddressPrefix
webAppSubnetNsgName: empty(webAppSubnetNsgName) ? toLower('${prefix}-webapp-subnet-nsg-${suffix}') : webAppSubnetNsgName
peSubnetName: peSubnetName
peSubnetAddressPrefix: peSubnetAddressPrefix
peSubnetNsgName: empty(peSubnetNsgName) ? toLower('${prefix}-pe-subnet-nsg-${suffix}') : peSubnetNsgName
natGatewayName: empty(natGatewayName) ? toLower('${prefix}-nat-gateway-${suffix}') : natGatewayName
natGatewayZones: natGatewayZones
natGatewayPublicIpPrefixName: toLower('${prefix}-nat-gateway-pip-prefix-${suffix}')
natGatewayPublicIpPrefixLength: natGatewayPublicIpPrefixLength
natGatewayIdleTimeoutMins: natGatewayIdleTimeoutMins
delegationServiceName: skuTier == 'FlexConsumption' ? 'Microsoft.App/environments' : 'Microsoft.Web/serverfarms'
workspaceId: workspace.id
location: location
tags: tags
}
}
module privateDnsZone 'modules/private-dns-zone.bicep' = {
name: 'privateDnsZone'
params: {
name: privateDnsZoneName
vnetId: network.outputs.virtualNetworkId
tags: tags
}
}
module privateEndpoints 'modules/private-endpoint.bicep' = {
name: 'privateEndpoints'
params: {
name: privateEndpointName
privateLinkServiceId: containerRegistry.id
privateDnsZoneId: privateDnsZone.outputs.id
vnetId: network.outputs.virtualNetworkId
subnetId: network.outputs.peSubnetId
groupIds: [
'registry'
]
location: location
tags: tags
}
}
module appServicePlan 'modules/app-service-plan.bicep' = {
name: 'appServicePlan'
params: {
name: appServicePlanName
location: location
skuName: skuName
skuTier: skuTier
kind: appServicePlanKind
reserved: reserved
zoneRedundant: zoneRedundant
workspaceId: workspace.id
tags: tags
}
}
module webApp 'modules/web-app.bicep' = {
name: webAppName
params: {
name: webAppName
location: location
kind: webAppKind
httpsOnly: httpsOnly
minTlsVersion: minTlsVersion
publicNetworkAccess: publicNetworkAccess
repoUrl: repoUrl
virtualNetworkName: network.outputs.virtualNetworkName
subnetName: network.outputs.webAppSubnetName
hostingPlanName: appServicePlan.outputs.name
loginServer: containerRegistry.properties.loginServer
imageName: imageName
imageTag: imageTag
managedIdentityName: managedIdentity.outputs.name
managedIdentityType: 'UserAssigned'
workspaceId: workspace.id
tags: tags
}
}
//********************************************
// Outputs
//********************************************
output appServicePlanName string = appServicePlan.outputs.name
output webAppName string = webApp.outputs.name
output acrName string = containerRegistry.name
output acrLoginServer string = containerRegistry.properties.loginServer
output managedIdentityName string = managedIdentity.outputs.name