-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.bicep
252 lines (240 loc) · 6.24 KB
/
main.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
@description('The Azure region to install it')
param location string = 'germanywestcentral'
@description('Base name for all resources')
param baseName string
@description('The password to access the /admin page of the Vaultwarden installation')
@secure()
param adminToken string
@description('If you are using sendgrid as a mail provider, set this to your API Key. If you are using another mail provider you have to customize the template.')
@secure()
param sendgridSmtpPassword string
@description('Enable VNet integration. NOTE: This will create additional components which produces additional costs.')
param enableVnetIntegrationWithAdditionalCosts bool = true
resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' = if (enableVnetIntegrationWithAdditionalCosts) {
name: 'vnet${baseName}'
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'default'
properties: {
addressPrefix: '10.0.0.0/23'
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [
location
]
}
]
}
}
]
}
}
resource logworkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
#disable-next-line BCP334
name: 'law${baseName}'
location: location
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 30
features: {
enableLogAccessUsingOnlyResourcePermissions: true
}
workspaceCapping: {
dailyQuotaGb: 1
}
publicNetworkAccessForIngestion: 'Enabled'
publicNetworkAccessForQuery: 'Enabled'
}
}
resource storage 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: 'stgvaultwarden${baseName}'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
properties: {
allowBlobPublicAccess: false
minimumTlsVersion: 'TLS1_2'
allowSharedKeyAccess: true
supportsHttpsTrafficOnly: true
accessTier: 'Hot'
networkAcls: {
defaultAction: enableVnetIntegrationWithAdditionalCosts ? 'Deny' : 'Allow'
bypass: 'AzureServices'
virtualNetworkRules: enableVnetIntegrationWithAdditionalCosts ? [
{
id: '${vnet.id}/subnets/default'
action: 'Allow'
}
] : null
}
}
}
resource fileservices 'Microsoft.Storage/storageAccounts/fileServices@2023-01-01' = {
name: 'default'
parent: storage
}
resource fileshare 'Microsoft.Storage/storageAccounts/fileServices/shares@2023-01-01' = {
name: 'vaultwarden'
parent: fileservices
properties: {
enabledProtocols: 'SMB'
shareQuota: 1024
}
}
resource managedEnv 'Microsoft.App/managedEnvironments@2023-05-01' = {
name: 'managedenv-${baseName}-vaultwarden'
location: location
properties: {
vnetConfiguration: {
internal: false
infrastructureSubnetId: enableVnetIntegrationWithAdditionalCosts ? vnet.properties.subnets[0].id : null
}
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logworkspace.properties.customerId
sharedKey: logworkspace.listKeys().primarySharedKey
}
}
}
}
resource managedEnvStorage 'Microsoft.App/managedEnvironments/storages@2023-05-01' = {
name: fileshare.name
parent: managedEnv
properties: {
azureFile: {
accessMode: 'ReadWrite'
shareName: fileshare.name
accountName: storage.name
accountKey: storage.listKeys().keys[0].value
}
}
}
resource vaultwardenapp 'Microsoft.App/containerApps@2023-05-01' = {
name: 'vaultwarden${baseName}'
location: location
properties: {
environmentId: managedEnv.id
configuration: {
secrets: [
{
name: 'fileshare-connectionstring'
value: 'DefaultEndpointsProtocol=https;AccountName=${storage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storage.listKeys().keys[0].value}'
}
{
name: 'admintoken'
value: adminToken
}
{
name: 'sendgridsmtppassword'
value: sendgridSmtpPassword
}
]
activeRevisionsMode: 'Single'
ingress: {
external: true
allowInsecure: false
targetPort: 80
transport: 'auto'
traffic: [
{
weight: 100
latestRevision: true
}
]
}
}
template: {
containers: [
{
image: 'docker.io/vaultwarden/server:latest'
name: 'vaultwarden'
resources: {
#disable-next-line BCP036
cpu: '0.25'
memory: '0.5Gi'
}
env: [
{
name: 'AZURE_STORAGEFILE_CONNECTIONSTRING'
secretRef: 'fileshare-connectionstring'
}
{
name: 'SIGNUPS_ALLOWED'
value: 'false'
}
{
name: 'ADMIN_TOKEN'
secretRef: 'admintoken'
}
{
name: 'SMTP_HOST'
value: 'smtp.sendgrid.net'
}
{
name: 'SMTP_FROM'
value: '[email protected]'
}
{
name: 'SMTP_PORT'
value: '465'
}
{
name: 'SMTP_SECURITY'
value: 'force_tls'
}
{
name: 'SMTP_USERNAME'
value: 'apikey'
}
{
name: 'SMTP_PASSWORD'
secretRef: 'sendgridsmtppassword'
}
{
name: 'SMTP_AUTH_MECHANISM'
value: 'Login'
}
{
name: 'ENABLE_DB_WAL'
value: 'true'
}
{
name: 'SHOW_PASSWORD_HINT'
value: 'false'
}
]
volumeMounts: [
{
volumeName: fileshare.name
mountPath: '/data'
}
]
}
]
volumes: [
{
name: fileshare.name
storageName: managedEnvStorage.name
storageType: 'AzureFile'
}
]
scale: {
minReplicas: 0
maxReplicas: 1
}
}
}
}