-
Notifications
You must be signed in to change notification settings - Fork 1
/
infra.bicep
215 lines (192 loc) · 4.83 KB
/
infra.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
targetScope = 'resourceGroup'
@description('The name of the environment. This will also suffix all resources. Lowercase and no space.')
param envName string
@description('Location for all resources.')
param location string = resourceGroup().location
@description('The name of the SKU to use when creating the Front Door profile.')
@allowed([
'Standard_AzureFrontDoor'
'Premium_AzureFrontDoor'
])
param frontDoorSkuName string = 'Standard_AzureFrontDoor'
param staticWebAppLocation string = 'West Europe'
// front door
resource frontDoorProfile 'Microsoft.Cdn/profiles@2021-06-01' = {
name: '${envName}-afd'
location: 'global'
sku: {
name: frontDoorSkuName
}
}
resource frontDoorEndpoint 'Microsoft.Cdn/profiles/afdEndpoints@2021-06-01' = {
name: '${envName}-afd'
parent: frontDoorProfile
location: 'global'
properties: {
enabledState: 'Enabled'
}
}
// Front Door - API
resource frontDoorOriginGroupApi 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = {
name: 'api'
parent: frontDoorProfile
properties: {
loadBalancingSettings: {
sampleSize: 4
successfulSamplesRequired: 3
}
healthProbeSettings: {
probePath: '/health'
probeRequestType: 'HEAD'
probeProtocol: 'Http'
probeIntervalInSeconds: 30
}
}
}
resource frontDoorOriginApi 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = {
name: 'api'
parent: frontDoorOriginGroupApi
properties: {
hostName: appService.properties.defaultHostName
httpPort: 80
httpsPort: 443
originHostHeader: appService.properties.defaultHostName
priority: 1
weight: 1000
}
}
resource frontDoorRouteApi 'Microsoft.Cdn/profiles/afdEndpoints/routes@2021-06-01' = {
name: 'api'
parent: frontDoorEndpoint
dependsOn: [
frontDoorOriginApi // This explicit dependency is required to ensure that the origin group is not empty when the route is created.
]
properties: {
originGroup: {
id: frontDoorOriginGroupApi.id
}
supportedProtocols: [
'Http'
'Https'
]
patternsToMatch: [
'/api/*'
]
forwardingProtocol: 'HttpsOnly'
linkToDefaultDomain: 'Enabled'
httpsRedirect: 'Enabled'
}
}
// Front Door - Spa
resource frontDoorOriginGroupSpa 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = {
name: 'spa'
parent: frontDoorProfile
properties: {
loadBalancingSettings: {
sampleSize: 4
successfulSamplesRequired: 3
}
healthProbeSettings: {
probePath: '/index.html'
probeRequestType: 'HEAD'
probeProtocol: 'Http'
probeIntervalInSeconds: 30
}
}
}
resource frontDoorOriginSpa 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = {
name: 'spa'
parent: frontDoorOriginGroupSpa
properties: {
hostName: staticWebApp.properties.defaultHostname
httpPort: 80
httpsPort: 443
originHostHeader: staticWebApp.properties.defaultHostname
priority: 1
weight: 1000
}
}
resource frontDoorRouteSpa 'Microsoft.Cdn/profiles/afdEndpoints/routes@2021-06-01' = {
name: 'spa'
parent: frontDoorEndpoint
dependsOn: [
frontDoorOriginSpa // This explicit dependency is required to ensure that the origin group is not empty when the route is created.
]
properties: {
originGroup: {
id: frontDoorOriginGroupSpa.id
}
supportedProtocols: [
'Http'
'Https'
]
patternsToMatch: [
'/*'
]
forwardingProtocol: 'HttpsOnly'
linkToDefaultDomain: 'Enabled'
httpsRedirect: 'Enabled'
}
}
// API backend
resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = {
name: '${envName}-plan'
location: location
properties: {
reserved: true
}
sku: {
name: 'F1'
}
kind: 'linux'
}
resource appService 'Microsoft.Web/sites@2020-06-01' = {
name: '${envName}-api'
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: appServicePlan.id
clientAffinityEnabled: false
siteConfig: {
linuxFxVersion: 'DOTNETCORE|6.0'
appSettings: [
{
name: 'WEBSITE_RUN_FROM_PACKAGE'
value: '1'
}
]
healthCheckPath: '/health'
ipSecurityRestrictions: [
{
tag: 'ServiceTag'
ipAddress: 'AzureFrontDoor.Backend'
action: 'Allow'
priority: 100
headers: {
'x-azure-fdid': [
frontDoorProfile.properties.frontDoorId
]
}
name: 'Allow traffic from Front Door'
}
]
}
}
}
// UI (static web app)
resource staticWebApp 'Microsoft.Web/staticSites@2021-01-15' = {
name: '${envName}-ui'
location: staticWebAppLocation
tags: null
properties: {
}
sku: {
name: 'Standard'
size: 'Standard'
}
}
// Outputs
output frontDoorId string = frontDoorProfile.id
output frontDoorEndpoint string = frontDoorEndpoint.properties.hostName