forked from microsoft/azure-redcap-paas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazuredeploy.bicep
334 lines (299 loc) · 8.28 KB
/
azuredeploy.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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
param location string = resourceGroup().location
@description('Name of azure web app')
param siteName string
@description('Stack settings')
param linuxFxVersion string = 'php|7.4'
@description('Database administrator login name')
@minLength(1)
param administratorLogin string = 'redcap_app'
@description('Database administrator password')
@minLength(8)
@secure()
param administratorLoginPassword string
@description('REDCap zip file URI.')
param redcapAppZip string = ''
@description('REDCap Community site username for downloading the REDCap zip file.')
param redcapCommunityUsername string
@description('REDCap Community site password for downloading the REDCap zip file.')
@secure()
param redcapCommunityPassword string
@description('REDCap zip file version to be downloaded from the REDCap Community site.')
param redcapAppZipVersion string = 'latest'
@description('Email address configured as the sending address in REDCap')
param fromEmailAddress string
@description('Fully-qualified domain name of your SMTP relay endpoint')
param smtpFQDN string
@description('Login name for your SMTP relay')
param smtpUser string
@description('Login password for your SMTP relay')
@secure()
param smtpPassword string
@description('Port for your SMTP relay')
param smtpPort string = '587'
@description('Describes plan\'s pricing tier and capacity - this can be changed after deployment. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/')
@allowed([
'F1'
'D1'
'B1'
'B2'
'B3'
'S1'
'S2'
'S3'
'P1v2'
'P2v2'
'P3v2'
'P1v3'
'P2v3'
'P3v3'
])
param skuName string = 'S1'
@description('Describes plan\'s instance count (how many distinct web servers will be deployed in the farm) - this can be changed after deployment')
@minValue(1)
param skuCapacity int = 1
@description('Initial MySQL database storage size in GB ')
param databaseStorageSizeGB int = 32
@description('Initial MySQL databse storage IOPS')
param databaseStorageIops int = 396
@allowed([
'Enabled'
'Disabled'
])
param databaseStorageAutoGrow string = 'Enabled'
@allowed([
'Enabled'
'Disabled'
])
param databseStorageAutoIoScaling string = 'Enabled'
@description('MySQL version')
@allowed([
'5.6'
'5.7'
])
param mysqlVersion string = '5.7'
@description('The default selected is \'Locally Redundant Storage\' (3 copies in one region). See https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy for more information.')
@allowed([
'Standard_LRS'
'Standard_ZRS'
'Standard_GRS'
'Standard_RAGRS'
'Premium_LRS'
])
param storageType string = 'Standard_LRS'
@description('Name of the container used to store backing files in the new storage account. This container is created automatically during deployment.')
param storageContainerName string = 'redcap'
@description('The path to the deployment source files on GitHub')
param repoURL string = 'https://github.com/microsoft/azure-redcap-paas.git'
@description('The main branch of the application repo')
param branch string = 'main'
var siteNameCleaned = replace(siteName, ' ', '')
var databaseName = '${siteNameCleaned}_db'
var uniqueServerName = '${siteNameCleaned}${uniqueString(resourceGroup().id)}'
var hostingPlanNameCleaned = '${siteNameCleaned}_serviceplan'
var uniqueWebSiteName = '${siteNameCleaned}${uniqueString(resourceGroup().id)}'
var uniqueStorageName = 'storage${uniqueString(resourceGroup().id)}'
var storageAccountId = '${resourceGroup().id}/providers/Microsoft.Storage/storageAccounts/${uniqueStorageName}'
resource storageName 'Microsoft.Storage/storageAccounts@2016-01-01' = {
name: uniqueStorageName
location: location
sku: {
name: storageType
}
tags: {
displayName: 'BackingStorage'
}
kind: 'Storage'
dependsOn: []
}
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2021-09-01' = {
name: 'default'
parent: storageName
}
resource storageContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-09-01' = {
name: storageContainerName
parent: blobServices
}
resource hostingPlanName 'Microsoft.Web/serverfarms@2016-09-01' = {
name: hostingPlanNameCleaned
location: location
tags: {
displayName: 'HostingPlan'
}
sku: {
name: skuName
capacity: skuCapacity
}
kind: 'linux'
properties: {
name: hostingPlanNameCleaned
reserved: true
}
}
resource webSiteName 'Microsoft.Web/sites@2016-08-01' = {
name: uniqueWebSiteName
location: location
tags: {
displayName: 'WebApp'
}
properties: {
name: uniqueWebSiteName
serverFarmId: hostingPlanNameCleaned
siteConfig: {
linuxFxVersion: linuxFxVersion
alwaysOn: true
appCommandLine: '/home/startup.sh'
appSettings: [
{
name: 'StorageContainerName'
value: storageContainerName
}
{
name: 'StorageAccount'
value: uniqueStorageName
}
{
name: 'StorageKey'
value: concat(listKeys(storageAccountId, '2015-05-01-preview').key1)
}
{
name: 'redcapAppZip'
value: redcapAppZip
}
{
name: 'redcapCommunityUsername'
value: redcapCommunityUsername
}
{
name: 'redcapCommunityPassword'
value: redcapCommunityPassword
}
{
name: 'redcapAppZipVersion'
value: redcapAppZipVersion
}
{
name: 'DBHostName'
value: '${uniqueServerName}.mysql.database.azure.com'
}
{
name: 'DBName'
value: databaseName
}
{
name: 'DBUserName'
value: administratorLogin
}
{
name: 'DBPassword'
value: administratorLoginPassword
}
{
name: 'DBSslCa'
value: '/home/site/wwwroot/DigiCertGlobalRootCA.crt.pem'
}
{
name: 'PHP_INI_SCAN_DIR'
value: '/usr/local/etc/php/conf.d:/home/site'
}
{
name: 'from_email_address'
value: fromEmailAddress
}
{
name: 'smtp_fqdn_name'
value: smtpFQDN
}
{
name: 'smtp_port'
value: smtpPort
}
{
name: 'smtp_user_name'
value: smtpUser
}
{
name: 'smtp_password'
value: smtpPassword
}
{
name: 'SCM_DO_BUILD_DURING_DEPLOYMENT'
value: '1'
}
]
}
}
dependsOn: [
hostingPlanName
storageName
]
}
resource webSiteName_web 'Microsoft.Web/sites/sourcecontrols@2015-08-01' = {
parent: webSiteName
name: 'web'
location: location
tags: {
displayName: 'CodeDeploy'
}
properties: {
repoUrl: repoURL
branch: branch
isManualIntegration: true
}
dependsOn: [
serverName
]
}
resource serverName 'Microsoft.DBforMySQL/flexibleServers@2021-12-01-preview' = {
location: location
name: uniqueServerName
tags: {
displayName: 'MySQLAzure'
}
properties: {
version: mysqlVersion
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
storage: {
storageSizeGB: databaseStorageSizeGB
iops: databaseStorageIops
autoGrow: databaseStorageAutoGrow
autoIoScaling: databseStorageAutoIoScaling
}
backup: {
backupRetentionDays: 7
geoRedundantBackup: 'Disabled'
}
highAvailability: {
mode: 'Disabled'
}
replicationRole: 'None'
}
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
}
resource serverName_AllowAzureIPs 'Microsoft.DBforMySQL/flexibleServers/firewallRules@2021-12-01-preview' = {
parent: serverName
name: 'AllowAzureIPs'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
dependsOn: [
serverName_databaseName
]
}
resource serverName_databaseName 'Microsoft.DBforMySQL/flexibleServers/databases@2021-12-01-preview' = {
parent: serverName
name: databaseName
properties: {
charset: 'utf8'
collation: 'utf8_general_ci'
}
}
output MySQLHostName string = '${uniqueServerName}.mysql.database.azure.com'
output MySqlUserName string = '${administratorLogin}@${uniqueServerName}'
output webSiteFQDN string = '${uniqueWebSiteName}.azurewebsites.net'
output storageAccountName string = uniqueStorageName
output storageContainerName string = storageContainerName