-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazuredeploy.bicep
More file actions
206 lines (193 loc) · 5.09 KB
/
azuredeploy.bicep
File metadata and controls
206 lines (193 loc) · 5.09 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
param environment_name string = 'env-${uniqueSuffix}'
param location string = resourceGroup().location
param uniqueSeed string = '${subscription().subscriptionId}-${resourceGroup().name}'
param uniqueSuffix string = uniqueString(uniqueSeed)
param storageAccountName string = 'storage${replace(uniqueSuffix, '-', '')}'
param blobContainerName string = 'orders'
param managedIdentityName string = 'nodeapp-identity'
var logAnalyticsWorkspaceName = 'logs-${environment_name}'
var appInsightsName = 'appins-${environment_name}'
resource logAnalyticsWorkspace'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: logAnalyticsWorkspaceName
location: location
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}
resource environment 'Microsoft.App/managedEnvironments@2022-03-01' = {
name: environment_name
location: location
properties: {
daprAIInstrumentationKey: reference(appInsights.id, '2020-02-02').InstrumentationKey
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: reference(logAnalyticsWorkspace.id, '2021-06-01').customerId
sharedKey: listKeys(logAnalyticsWorkspace.id, '2021-06-01').primarySharedKey
}
}
}
}
// Storage Account to act as state store
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2021-06-01' = {
parent: storageAccount
name: 'default'
}
resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-06-01' = {
parent: blobService
name: blobContainerName
}
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
name: managedIdentityName
location: location
}
// Grant permissions for the container app to write to Azure Blob via Managed Identity
@description('This is the built-in Storage Blob Data Contributor role. See https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#storage-blob-data-contributor')
resource contributorRoleDefinition 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
scope: storageAccount
name: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
}
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid(resourceGroup().id, contributorRoleDefinition.id)
properties: {
roleDefinitionId: contributorRoleDefinition.id
principalId: managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
}
// Dapr state store component
resource daprComponent 'Microsoft.App/managedEnvironments/daprComponents@2022-03-01' = {
name: 'statestore'
parent: environment
properties: {
componentType: 'state.azure.blobstorage'
version: 'v1'
ignoreErrors: false
initTimeout: '5s'
metadata: [
{
name: 'accountName'
value: storageAccountName
}
{
name: 'containerName'
value: blobContainerName
}
{
name: 'azureClientId'
value: managedIdentity.properties.clientId
}
]
scopes: [
'nodeapp'
]
}
dependsOn: [
storageAccount
]
}
resource nodeapp 'Microsoft.App/containerApps@2022-03-01' = {
name: 'nodeapp'
location: location
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}' : {}
}
}
properties: {
managedEnvironmentId: environment.id
configuration: {
ingress: {
external: false
targetPort: 3000
}
dapr: {
enabled: true
appId: 'nodeapp'
appProtocol: 'http'
appPort: 3000
}
}
template: {
containers: [
{
image: 'dapriosamples/hello-k8s-node:latest'
name: 'hello-k8s-node'
env: [
{
name: 'APP_PORT'
value: '3000'
}
]
resources: {
cpu: json('0.5')
memory: '1.0Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
dependsOn: [
daprComponent
]
}
resource pythonapp 'Microsoft.App/containerApps@2022-03-01' = {
name: 'pythonapp'
location: location
properties: {
managedEnvironmentId: environment.id
configuration: {
dapr: {
enabled: true
appId: 'pythonapp'
}
}
template: {
containers: [
{
image: 'dapriosamples/hello-k8s-python:latest'
name: 'hello-k8s-python'
resources: {
cpu: json('0.5')
memory: '1.0Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
dependsOn: [
nodeapp
]
}