-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bicep
157 lines (138 loc) · 4.85 KB
/
build.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
targetScope = 'resourceGroup'
param authClientId string
@secure()
param authClientSecret string
var functionAppName = 'secure-${uniqueString(resourceGroup().id)}'
var appServicePlanName = 'secure-asp'
var appInsightsName = 'secure-ai'
var sqlserverName = 'secure-${uniqueString(resourceGroup().id)}'
var storageAccountName = 'secure${uniqueString(resourceGroup().id)}'
var databaseName = 'secure-db'
var sqlAdministratorLogin = 'adminuser'
var sqlAdministratorLoginPassword = 'Ab!${uniqueString(resourceGroup().id)}${uniqueString(resourceGroup().id)}'
var sourceControlRepoUrl = 'https://github.com/arincoau/four-tips-securing-serverless'
var sourceControlBranch = 'main'
resource sqlServer 'Microsoft.Sql/servers@2019-06-01-preview' = {
name: sqlserverName
location: resourceGroup().location
properties: {
administratorLogin: sqlAdministratorLogin
administratorLoginPassword: sqlAdministratorLoginPassword
version: '12.0'
}
resource firewallRules 'firewallRules@2021-02-01-preview' = {
name: 'AllowAllWindowsAzureIps'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
resource database 'databases@2021-02-01-preview' = {
name: databaseName
location: resourceGroup().location
properties: {
sampleName: 'AdventureWorksLT'
}
}
}
resource appServicePlan 'Microsoft.Web/serverfarms@2018-02-01' = {
name: appServicePlanName
location: resourceGroup().location
sku: {
name: 'EP1'
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageAccountName
location: resourceGroup().location
sku: {
name: 'Standard_LRS'
}
kind: 'Storage'
properties: {
minimumTlsVersion: 'TLS1_2'
supportsHttpsTrafficOnly: true
}
resource fileServices 'fileServices@2021-04-01' = {
name: 'default'
resource fileShare 'shares@2021-04-01' = {
name: functionApp.name
}
}
}
resource functionApp 'Microsoft.Web/sites@2021-01-15' = {
name: functionAppName
location: resourceGroup().location
kind: 'functionapp'
properties: {
serverFarmId: appServicePlan.id
}
resource appSettings 'config@2021-01-15' = {
name: 'appsettings'
properties: {
AzureWebJobsStorage: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, '2019-06-01').keys[0].value}'
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, '2019-06-01').keys[0].value}'
APPINSIGHTS_INSTRUMENTATIONKEY: '${applicationInsights.properties.InstrumentationKey}'
WEBSITE_SKIP_CONTENTSHARE_VALIDATION: '1'
WEBSITE_CONTENTSHARE: '${functionApp.name}'
FUNCTIONS_EXTENSION_VERSION: '~3'
FUNCTIONS_WORKER_RUNTIME: 'dotnet'
SCM_COMMAND_IDLE_TIMEOUT: '10000'
WEBJOBS_IDLE_TIMEOUT: '10000'
MICROSOFT_PROVIDER_AUTHENTICATION_SECRET: authClientSecret
}
}
resource connectionstrings 'config@2021-01-15' = {
name: 'connectionstrings'
properties: {
AdventureWorks: {
type: 'SQLAzure'
value: 'Server=tcp:${sqlServer.name}${environment().suffixes.sqlServerHostname},1433;Database=${databaseName};User ID=${sqlAdministratorLogin};Password=${sqlAdministratorLoginPassword}'
}
}
}
resource sourceControl 'sourcecontrols@2020-12-01' = {
name: 'web'
properties: {
repoUrl: sourceControlRepoUrl
branch: sourceControlBranch
isManualIntegration: true
}
}
resource authSettings 'config@2020-12-01' = {
name: 'authsettingsV2'
properties: {
globalValidation: {
requireAuthentication: true
unauthenticatedClientAction: 'Return401'
redirectToProvider: 'azureactivedirectory'
}
identityProviders: {
azureActiveDirectory: {
enabled: true
registration: {
openIdIssuer: 'https://sts.windows.net/${subscription().tenantId}'
clientId: authClientId
clientSecretSettingName: 'MICROSOFT_PROVIDER_AUTHENTICATION_SECRET'
}
validation: {
allowedAudiences: [
'api://${authClientId}'
]
}
}
}
}
}
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
kind: 'web'
location: resourceGroup().location
properties: {
Application_Type: 'web'
}
}
output functionAppTestUrl string = 'https://${functionApp.properties.defaultHostName}/api/TopFiveProducts'
output functionAppName string = '${functionApp.name}'
output sqlServerName string = '${sqlServer.name}'