forked from CarloKuip/LapAroundBicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-demo.bicep
170 lines (159 loc) · 4.08 KB
/
main-demo.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
//parameters
param projectName string = 'bicep-demo'
//variables
var suffix= uniqueString(subscription().subscriptionId, subscription().tenantId)
//string interpolation
var uniqueName = '${projectName}-${suffix}'
var identityName = 'id-${uniqueName}'
var kvname = 'kv-${take(uniqueName, 9)}'
var workspaceName = 'workspace-${uniqueName}'
var insightsName = 'insights-${uniqueName}'
var hostingplanName = 'serviceplan-${uniqueName}'
var storageName = 'st${suffix}'
//resource definitions
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: identityName
location: resourceGroup().location
}
resource keyVault 'Microsoft.KeyVault/vaults@2021-04-01-preview' = {
name: kvname
location: resourceGroup().location
properties: {
enabledForDeployment: true
enabledForTemplateDeployment: true
enabledForDiskEncryption: true
tenantId: subscription().tenantId
sku: {
name: 'standard'
family: 'A'
}
enableRbacAuthorization: true
}
}
resource loganalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-10-01' ={
name: workspaceName
location: resourceGroup().location
properties:{
sku:{
name:'Free'
}
}
}
// resource dependency
resource appInsights 'Microsoft.Insights/components@2020-02-02-preview'={
name: insightsName
location: resourceGroup().location
kind: 'web'
properties:{
Application_Type:'web'
WorkspaceResourceId:loganalyticsWorkspace.id
}
dependsOn:[
loganalyticsWorkspace
]
}
resource appServicePlan 'Microsoft.Web/serverfarms@2020-12-01'={
name: hostingplanName
location: resourceGroup().location
kind: 'linux'
properties:{
targetWorkerSizeId:0
targetWorkerCount:1
reserved:true
}
sku:{
name: 'Y1'
tier: 'Dynamic'
}
}
resource functionAppStorage 'Microsoft.Storage/storageAccounts@2021-04-01'={
name: storageName
location: resourceGroup().location
kind:'StorageV2'
sku:{
name:'Standard_ZRS'
tier:'Standard'
}
properties:{
accessTier: 'Hot'
allowBlobPublicAccess: false
supportsHttpsTrafficOnly: true
}
}
var blobNames = [
'incoming'
'outgoing'
'quarantine'
]
resource storagecontainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-04-01' = [ for blobname in blobNames: {
name: '${storageName}/default/${blobname}'
dependsOn:[
functionAppStorage
]
}]
resource PSfunctionApp 'Microsoft.Web/sites@2020-12-01' = {
name: 'function-${uniqueName}'
kind:'functionapp,linux'
location: resourceGroup().location
identity: {
type:'UserAssigned'
userAssignedIdentities:{
'${managedIdentity.id}': {}
}
}
properties:{
serverFarmId: appServicePlan.id
enabled: true
siteConfig:{
alwaysOn:false
appSettings:[
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: appInsights.properties.InstrumentationKey
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: appInsights.properties.ConnectionString
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~3'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'powershell'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME_VERSION'
value: '~7'
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${functionAppStorage.name};AccountKey=${listKeys(functionAppStorage.id, '2019-06-01').keys[0].value};EndpointSuffix=core.windows.net'
}
]
}
keyVaultReferenceIdentity:managedIdentity.id
}
dependsOn:[
keyVault
functionAppStorage
appServicePlan
]
}
module kvroleassignment 'kv-role-assignment-module.bicep' = {
name: 'managedIdentityKeyVaultRole'
scope: resourceGroup()
params:{
identityName: managedIdentity.name
keyVaultName: keyVault.name
}
}
module stroleassignment 'st-role-assignment-module.bicep' ={
name: 'managedIdentityStorageRole'
scope: resourceGroup()
params: {
storageName: functionAppStorage.name
identityName: managedIdentity.name
}
}