-
Notifications
You must be signed in to change notification settings - Fork 376
/
main.bicep
835 lines (716 loc) · 34.7 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
metadata name = 'Storage Accounts'
metadata description = 'This module deploys a Storage Account.'
metadata owner = 'Azure/module-maintainers'
@maxLength(24)
@description('Required. Name of the Storage Account. Must be lower-case.')
param name string
@description('Optional. Location for all resources.')
param location string = resourceGroup().location
@description('Optional. Array of role assignments to create.')
param roleAssignments roleAssignmentType
@description('Optional. The managed identity definition for this resource.')
param managedIdentities managedIdentitiesType
@allowed([
'Storage'
'StorageV2'
'BlobStorage'
'FileStorage'
'BlockBlobStorage'
])
@description('Optional. Type of Storage Account to create.')
param kind string = 'StorageV2'
@allowed([
'Standard_LRS'
'Standard_GRS'
'Standard_RAGRS'
'Standard_ZRS'
'Premium_LRS'
'Premium_ZRS'
'Standard_GZRS'
'Standard_RAGZRS'
])
@description('Optional. Storage Account Sku Name.')
param skuName string = 'Standard_GRS'
@allowed([
'Premium'
'Hot'
'Cool'
])
@description('Conditional. Required if the Storage Account kind is set to BlobStorage. The access tier is used for billing. The "Premium" access tier is the default value for premium block blobs storage account type and it cannot be changed for the premium block blobs storage account type.')
param accessTier string = 'Hot'
@allowed([
'Disabled'
'Enabled'
])
@description('Optional. Allow large file shares if sets to \'Enabled\'. It cannot be disabled once it is enabled. Only supported on locally redundant and zone redundant file shares. It cannot be set on FileStorage storage accounts (storage accounts for premium file shares).')
param largeFileSharesState string = 'Disabled'
@description('Optional. Provides the identity based authentication settings for Azure Files.')
param azureFilesIdentityBasedAuthentication object = {}
@description('Optional. A boolean flag which indicates whether the default authentication is OAuth or not.')
param defaultToOAuthAuthentication bool = false
@description('Optional. Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. If false, then all requests, including shared access signatures, must be authorized with Azure Active Directory (Azure AD). The default value is null, which is equivalent to true.')
param allowSharedKeyAccess bool = true
@description('Optional. Configuration details for private endpoints. For security reasons, it is recommended to use private endpoints whenever possible.')
param privateEndpoints privateEndpointType
@description('Optional. The Storage Account ManagementPolicies Rules.')
param managementPolicyRules array?
@description('Optional. Networks ACLs, this value contains IPs to whitelist and/or Subnet information. If in use, bypass needs to be supplied. For security reasons, it is recommended to set the DefaultAction Deny.')
param networkAcls networkAclsType?
@description('Optional. A Boolean indicating whether or not the service applies a secondary layer of encryption with platform managed keys for data at rest. For security reasons, it is recommended to set it to true.')
param requireInfrastructureEncryption bool = true
@description('Optional. Allow or disallow cross AAD tenant object replication.')
param allowCrossTenantReplication bool = false
@description('Optional. Sets the custom domain name assigned to the storage account. Name is the CNAME source.')
param customDomainName string = ''
@description('Optional. Indicates whether indirect CName validation is enabled. This should only be set on updates.')
param customDomainUseSubDomainName bool = false
@description('Optional. Allows you to specify the type of endpoint. Set this to AzureDNSZone to create a large number of accounts in a single subscription, which creates accounts in an Azure DNS Zone and the endpoint URL will have an alphanumeric DNS Zone identifier.')
@allowed([
''
'AzureDnsZone'
'Standard'
])
param dnsEndpointType string = ''
@description('Optional. Blob service and containers to deploy.')
param blobServices object = kind != 'FileStorage'
? {
containerDeleteRetentionPolicyEnabled: true
containerDeleteRetentionPolicyDays: 7
deleteRetentionPolicyEnabled: true
deleteRetentionPolicyDays: 6
}
: {}
@description('Optional. File service and shares to deploy.')
param fileServices object = {}
@description('Optional. Queue service and queues to create.')
param queueServices object = {}
@description('Optional. Table service and tables to create.')
param tableServices object = {}
@description('Optional. Indicates whether public access is enabled for all blobs or containers in the storage account. For security reasons, it is recommended to set it to false.')
param allowBlobPublicAccess bool = false
@allowed([
'TLS1_0'
'TLS1_1'
'TLS1_2'
])
@description('Optional. Set the minimum TLS version on request to storage.')
param minimumTlsVersion string = 'TLS1_2'
@description('Conditional. If true, enables Hierarchical Namespace for the storage account. Required if enableSftp or enableNfsV3 is set to true.')
param enableHierarchicalNamespace bool = false
@description('Optional. If true, enables Secure File Transfer Protocol for the storage account. Requires enableHierarchicalNamespace to be true.')
param enableSftp bool = false
@description('Optional. Local users to deploy for SFTP authentication.')
param localUsers array = []
@description('Optional. Enables local users feature, if set to true.')
param isLocalUserEnabled bool = false
@description('Optional. If true, enables NFS 3.0 support for the storage account. Requires enableHierarchicalNamespace to be true.')
param enableNfsV3 bool = false
@description('Optional. The diagnostic settings of the service.')
param diagnosticSettings diagnosticSettingType
@description('Optional. The lock settings of the service.')
param lock lockType
@description('Optional. Tags of the resource.')
param tags object?
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
@description('Optional. Restrict copy to and from Storage Accounts within an AAD tenant or with Private Links to the same VNet.')
@allowed([
''
'AAD'
'PrivateLink'
])
param allowedCopyScope string = ''
@description('Optional. Whether or not public network access is allowed for this resource. For security reasons it should be disabled. If not specified, it will be disabled by default if private endpoints are set and networkAcls are not set.')
@allowed([
''
'Enabled'
'Disabled'
])
param publicNetworkAccess string = ''
@description('Optional. Allows HTTPS traffic only to storage service if sets to true.')
param supportsHttpsTrafficOnly bool = true
@description('Optional. The customer managed key definition.')
param customerManagedKey customerManagedKeyType
@description('Optional. The SAS expiration period. DD.HH:MM:SS.')
param sasExpirationPeriod string = ''
@description('Optional. The keyType to use with Queue & Table services.')
@allowed([
'Account'
'Service'
])
param keyType string?
var supportsBlobService = kind == 'BlockBlobStorage' || kind == 'BlobStorage' || kind == 'StorageV2' || kind == 'Storage'
var supportsFileService = kind == 'FileStorage' || kind == 'StorageV2' || kind == 'Storage'
var formattedUserAssignedIdentities = reduce(
map((managedIdentities.?userAssignedResourceIds ?? []), (id) => { '${id}': {} }),
{},
(cur, next) => union(cur, next)
) // Converts the flat array to an object like { '${id1}': {}, '${id2}': {} }
var identity = !empty(managedIdentities)
? {
type: (managedIdentities.?systemAssigned ?? false)
? (!empty(managedIdentities.?userAssignedResourceIds ?? {}) ? 'SystemAssigned,UserAssigned' : 'SystemAssigned')
: (!empty(managedIdentities.?userAssignedResourceIds ?? {}) ? 'UserAssigned' : 'None')
userAssignedIdentities: !empty(formattedUserAssignedIdentities) ? formattedUserAssignedIdentities : null
}
: null
var builtInRoleNames = {
Contributor: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
Owner: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635')
Reader: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')
'Reader and Data Access': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'c12c1c16-33a1-487b-954d-41c89c60f349'
)
'Role Based Access Control Administrator (Preview)': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'f58310d9-a9f6-439a-9e8d-f62e7b41a168'
)
'Storage Account Backup Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'e5e2a7ff-d759-4cd2-bb51-3152d37e2eb1'
)
'Storage Account Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'17d1049b-9a84-46fb-8f53-869881c3d3ab'
)
'Storage Account Key Operator Service Role': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'81a9662b-bebf-436f-a333-f67b29880f12'
)
'Storage Blob Data Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
)
'Storage Blob Data Owner': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'b7e6dc6d-f1e8-4753-8033-0f276bb0955b'
)
'Storage Blob Data Reader': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'2a2b9908-6ea1-4ae2-8e65-a410df84e7d1'
)
'Storage Blob Delegator': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'db58b8e5-c6ad-4a2a-8342-4190687cbf4a'
)
'Storage File Data SMB Share Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'0c867c2a-1d8c-454a-a3db-ab2ea1bdc8bb'
)
'Storage File Data SMB Share Elevated Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'a7264617-510b-434b-a828-9731dc254ea7'
)
'Storage File Data SMB Share Reader': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'aba4ae5f-2193-4029-9191-0cb91df5e314'
)
'Storage Queue Data Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'974c5e8b-45b9-4653-ba55-5f855dd0fb88'
)
'Storage Queue Data Message Processor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'8a0f0c08-91a1-4084-bc3d-661d67233fed'
)
'Storage Queue Data Message Sender': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'c6a89b2d-59bc-44d0-9896-0f6e12d7b80a'
)
'Storage Queue Data Reader': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'19e7f393-937e-4f77-808e-94535e297925'
)
'Storage Table Data Contributor': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3'
)
'Storage Table Data Reader': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'76199698-9eea-4c19-bc75-cec21354c6b6'
)
'User Access Administrator': subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'18d7d88d-d35e-4fb5-a5c3-7773c20a72d9'
)
}
#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableTelemetry) {
name: '46d3xbcp.res.storage-storageaccount.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}
resource cMKKeyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId)) {
name: last(split((customerManagedKey.?keyVaultResourceId ?? 'dummyVault'), '/'))
scope: resourceGroup(
split((customerManagedKey.?keyVaultResourceId ?? '//'), '/')[2],
split((customerManagedKey.?keyVaultResourceId ?? '////'), '/')[4]
)
resource cMKKey 'keys@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId) && !empty(customerManagedKey.?keyName)) {
name: customerManagedKey.?keyName ?? 'dummyKey'
}
}
resource cMKUserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = if (!empty(customerManagedKey.?userAssignedIdentityResourceId)) {
name: last(split(customerManagedKey.?userAssignedIdentityResourceId ?? 'dummyMsi', '/'))
scope: resourceGroup(
split((customerManagedKey.?userAssignedIdentityResourceId ?? '//'), '/')[2],
split((customerManagedKey.?userAssignedIdentityResourceId ?? '////'), '/')[4]
)
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: name
location: location
kind: kind
sku: {
name: skuName
}
identity: identity
tags: tags
properties: {
allowSharedKeyAccess: allowSharedKeyAccess
defaultToOAuthAuthentication: defaultToOAuthAuthentication
allowCrossTenantReplication: allowCrossTenantReplication
allowedCopyScope: !empty(allowedCopyScope) ? allowedCopyScope : null
customDomain: {
name: customDomainName
useSubDomainName: customDomainUseSubDomainName
}
dnsEndpointType: !empty(dnsEndpointType) ? dnsEndpointType : null
isLocalUserEnabled: isLocalUserEnabled
encryption: union(
{
keySource: !empty(customerManagedKey) ? 'Microsoft.Keyvault' : 'Microsoft.Storage'
services: {
blob: supportsBlobService
? {
enabled: true
}
: null
file: supportsFileService
? {
enabled: true
}
: null
table: {
enabled: true
keyType: keyType
}
queue: {
enabled: true
keyType: keyType
}
}
keyvaultproperties: !empty(customerManagedKey)
? {
keyname: customerManagedKey!.keyName
keyvaulturi: cMKKeyVault.properties.vaultUri
keyversion: !empty(customerManagedKey.?keyVersion ?? '')
? customerManagedKey!.keyVersion
: last(split(cMKKeyVault::cMKKey.properties.keyUriWithVersion, '/'))
}
: null
identity: {
userAssignedIdentity: !empty(customerManagedKey.?userAssignedIdentityResourceId)
? cMKUserAssignedIdentity.id
: null
}
},
(requireInfrastructureEncryption
? {
requireInfrastructureEncryption: kind != 'Storage' ? requireInfrastructureEncryption : null
}
: {})
)
accessTier: (kind != 'Storage' && kind != 'BlockBlobStorage') ? accessTier : null
sasPolicy: !empty(sasExpirationPeriod)
? {
expirationAction: 'Log'
sasExpirationPeriod: sasExpirationPeriod
}
: null
supportsHttpsTrafficOnly: supportsHttpsTrafficOnly
isHnsEnabled: enableHierarchicalNamespace ? enableHierarchicalNamespace : null
isSftpEnabled: enableSftp
isNfsV3Enabled: enableNfsV3 ? enableNfsV3 : any('')
largeFileSharesState: (skuName == 'Standard_LRS') || (skuName == 'Standard_ZRS') ? largeFileSharesState : null
minimumTlsVersion: minimumTlsVersion
networkAcls: !empty(networkAcls)
? union(
{
resourceAccessRules: networkAcls.?resourceAccessRules
defaultAction: networkAcls.?defaultAction ?? 'Deny'
virtualNetworkRules: networkAcls.?virtualNetworkRules
ipRules: networkAcls.?ipRules
},
(contains(networkAcls!, 'bypass') ? { bypass: networkAcls.?bypass } : {}) // setting `bypass` to `null`is not supported
)
: {
// New default case that enables the firewall by default
bypass: 'AzureServices'
defaultAction: 'Deny'
}
allowBlobPublicAccess: allowBlobPublicAccess
publicNetworkAccess: !empty(publicNetworkAccess)
? any(publicNetworkAccess)
: (!empty(privateEndpoints) && empty(networkAcls) ? 'Disabled' : null)
azureFilesIdentityBasedAuthentication: !empty(azureFilesIdentityBasedAuthentication)
? azureFilesIdentityBasedAuthentication
: null
}
}
resource storageAccount_diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
for (diagnosticSetting, index) in (diagnosticSettings ?? []): {
name: diagnosticSetting.?name ?? '${name}-diagnosticSettings'
properties: {
storageAccountId: diagnosticSetting.?storageAccountResourceId
workspaceId: diagnosticSetting.?workspaceResourceId
eventHubAuthorizationRuleId: diagnosticSetting.?eventHubAuthorizationRuleResourceId
eventHubName: diagnosticSetting.?eventHubName
metrics: [
for group in (diagnosticSetting.?metricCategories ?? [{ category: 'AllMetrics' }]): {
category: group.category
enabled: group.?enabled ?? true
timeGrain: null
}
]
marketplacePartnerId: diagnosticSetting.?marketplacePartnerResourceId
logAnalyticsDestinationType: diagnosticSetting.?logAnalyticsDestinationType
}
scope: storageAccount
}
]
resource storageAccount_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: storageAccount
}
resource storageAccount_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [
for (roleAssignment, index) in (roleAssignments ?? []): {
name: guid(storageAccount.id, roleAssignment.principalId, roleAssignment.roleDefinitionIdOrName)
properties: {
roleDefinitionId: contains(builtInRoleNames, roleAssignment.roleDefinitionIdOrName)
? builtInRoleNames[roleAssignment.roleDefinitionIdOrName]
: contains(roleAssignment.roleDefinitionIdOrName, '/providers/Microsoft.Authorization/roleDefinitions/')
? roleAssignment.roleDefinitionIdOrName
: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleAssignment.roleDefinitionIdOrName)
principalId: roleAssignment.principalId
description: roleAssignment.?description
principalType: roleAssignment.?principalType
condition: roleAssignment.?condition
conditionVersion: !empty(roleAssignment.?condition) ? (roleAssignment.?conditionVersion ?? '2.0') : null // Must only be set if condtion is set
delegatedManagedIdentityResourceId: roleAssignment.?delegatedManagedIdentityResourceId
}
scope: storageAccount
}
]
module storageAccount_privateEndpoints 'br/public:avm/res/network/private-endpoint:0.4.1' = [
for (privateEndpoint, index) in (privateEndpoints ?? []): {
name: '${uniqueString(deployment().name, location)}-storageAccount-PrivateEndpoint-${index}'
scope: resourceGroup(privateEndpoint.?resourceGroupName ?? '')
params: {
name: privateEndpoint.?name ?? 'pep-${last(split(storageAccount.id, '/'))}-${privateEndpoint.service}-${index}'
privateLinkServiceConnections: privateEndpoint.?isManualConnection != true
? [
{
name: privateEndpoint.?privateLinkServiceConnectionName ?? '${last(split(storageAccount.id, '/'))}-${privateEndpoint.service}-${index}'
properties: {
privateLinkServiceId: storageAccount.id
groupIds: [
privateEndpoint.service
]
}
}
]
: null
manualPrivateLinkServiceConnections: privateEndpoint.?isManualConnection == true
? [
{
name: privateEndpoint.?privateLinkServiceConnectionName ?? '${last(split(storageAccount.id, '/'))}-${privateEndpoint.service}-${index}'
properties: {
privateLinkServiceId: storageAccount.id
groupIds: [
privateEndpoint.service
]
requestMessage: privateEndpoint.?manualConnectionRequestMessage ?? 'Manual approval required.'
}
}
]
: null
subnetResourceId: privateEndpoint.subnetResourceId
enableTelemetry: privateEndpoint.?enableTelemetry ?? enableTelemetry
location: privateEndpoint.?location ?? reference(
split(privateEndpoint.subnetResourceId, '/subnets/')[0],
'2020-06-01',
'Full'
).location
lock: privateEndpoint.?lock ?? lock
privateDnsZoneGroupName: privateEndpoint.?privateDnsZoneGroupName
privateDnsZoneResourceIds: privateEndpoint.?privateDnsZoneResourceIds
roleAssignments: privateEndpoint.?roleAssignments
tags: privateEndpoint.?tags ?? tags
customDnsConfigs: privateEndpoint.?customDnsConfigs
ipConfigurations: privateEndpoint.?ipConfigurations
applicationSecurityGroupResourceIds: privateEndpoint.?applicationSecurityGroupResourceIds
customNetworkInterfaceName: privateEndpoint.?customNetworkInterfaceName
}
}
]
// Lifecycle Policy
module storageAccount_managementPolicies 'management-policy/main.bicep' = if (!empty(managementPolicyRules ?? [])) {
name: '${uniqueString(deployment().name, location)}-Storage-ManagementPolicies'
params: {
storageAccountName: storageAccount.name
rules: managementPolicyRules ?? []
}
dependsOn: [
storageAccount_blobServices // To ensure the lastAccessTimeTrackingPolicy is set first (if used in rule)
]
}
// SFTP user settings
module storageAccount_localUsers 'local-user/main.bicep' = [
for (localUser, index) in localUsers: {
name: '${uniqueString(deployment().name, location)}-Storage-LocalUsers-${index}'
params: {
storageAccountName: storageAccount.name
name: localUser.name
hasSshKey: localUser.hasSshKey
hasSshPassword: localUser.hasSshPassword
permissionScopes: localUser.permissionScopes
hasSharedKey: localUser.?hasSharedKey
homeDirectory: localUser.?homeDirectory
sshAuthorizedKeys: localUser.?sshAuthorizedKeys
}
}
]
// Containers
module storageAccount_blobServices 'blob-service/main.bicep' = if (!empty(blobServices)) {
name: '${uniqueString(deployment().name, location)}-Storage-BlobServices'
params: {
storageAccountName: storageAccount.name
containers: blobServices.?containers
automaticSnapshotPolicyEnabled: blobServices.?automaticSnapshotPolicyEnabled
changeFeedEnabled: blobServices.?changeFeedEnabled
changeFeedRetentionInDays: blobServices.?changeFeedRetentionInDays
containerDeleteRetentionPolicyEnabled: blobServices.?containerDeleteRetentionPolicyEnabled
containerDeleteRetentionPolicyDays: blobServices.?containerDeleteRetentionPolicyDays
containerDeleteRetentionPolicyAllowPermanentDelete: blobServices.?containerDeleteRetentionPolicyAllowPermanentDelete
corsRules: blobServices.?corsRules
defaultServiceVersion: blobServices.?defaultServiceVersion
deleteRetentionPolicyAllowPermanentDelete: blobServices.?deleteRetentionPolicyAllowPermanentDelete
deleteRetentionPolicyEnabled: blobServices.?deleteRetentionPolicyEnabled
deleteRetentionPolicyDays: blobServices.?deleteRetentionPolicyDays
isVersioningEnabled: blobServices.?isVersioningEnabled
lastAccessTimeTrackingPolicyEnabled: blobServices.?lastAccessTimeTrackingPolicyEnabled
restorePolicyEnabled: blobServices.?restorePolicyEnabled
restorePolicyDays: blobServices.?restorePolicyDays
diagnosticSettings: blobServices.?diagnosticSettings
}
}
// File Shares
module storageAccount_fileServices 'file-service/main.bicep' = if (!empty(fileServices)) {
name: '${uniqueString(deployment().name, location)}-Storage-FileServices'
params: {
storageAccountName: storageAccount.name
diagnosticSettings: fileServices.?diagnosticSettings
protocolSettings: fileServices.?protocolSettings
shareDeleteRetentionPolicy: fileServices.?shareDeleteRetentionPolicy
shares: fileServices.?shares
}
}
// Queue
module storageAccount_queueServices 'queue-service/main.bicep' = if (!empty(queueServices)) {
name: '${uniqueString(deployment().name, location)}-Storage-QueueServices'
params: {
storageAccountName: storageAccount.name
diagnosticSettings: queueServices.?diagnosticSettings
queues: queueServices.?queues
}
}
// Table
module storageAccount_tableServices 'table-service/main.bicep' = if (!empty(tableServices)) {
name: '${uniqueString(deployment().name, location)}-Storage-TableServices'
params: {
storageAccountName: storageAccount.name
diagnosticSettings: tableServices.?diagnosticSettings
tables: tableServices.?tables
}
}
@description('The resource ID of the deployed storage account.')
output resourceId string = storageAccount.id
@description('The name of the deployed storage account.')
output name string = storageAccount.name
@description('The resource group of the deployed storage account.')
output resourceGroupName string = resourceGroup().name
@description('The primary blob endpoint reference if blob services are deployed.')
output primaryBlobEndpoint string = !empty(blobServices) && contains(blobServices, 'containers')
? reference('Microsoft.Storage/storageAccounts/${storageAccount.name}', '2019-04-01').primaryEndpoints.blob
: ''
@description('The principal ID of the system assigned identity.')
output systemAssignedMIPrincipalId string = storageAccount.?identity.?principalId ?? ''
@description('The location the resource was deployed into.')
output location string = storageAccount.location
@description('All service endpoints of the deployed storage account, Note Standard_LRS and Standard_ZRS accounts only have a blob service endpoint.')
output serviceEndpoints object = storageAccount.properties.primaryEndpoints
// =============== //
// Definitions //
// =============== //
type managedIdentitiesType = {
@description('Optional. Enables system assigned managed identity on the resource.')
systemAssigned: bool?
@description('Optional. The resource ID(s) to assign to the resource.')
userAssignedResourceIds: string[]?
}?
type lockType = {
@description('Optional. Specify the name of lock.')
name: string?
@description('Optional. Specify the type of lock.')
kind: ('CanNotDelete' | 'ReadOnly' | 'None')?
}?
type roleAssignmentType = {
@description('Required. The role to assign. You can provide either the display name of the role definition, the role definition GUID, or its fully qualified ID in the following format: \'/providers/Microsoft.Authorization/roleDefinitions/c2f4ef07-c644-48eb-af81-4b1b4947fb11\'.')
roleDefinitionIdOrName: string
@description('Required. The principal ID of the principal (user/group/identity) to assign the role to.')
principalId: string
@description('Optional. The principal type of the assigned principal ID.')
principalType: ('ServicePrincipal' | 'Group' | 'User' | 'ForeignGroup' | 'Device')?
@description('Optional. The description of the role assignment.')
description: string?
@description('Optional. The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase "foo_storage_container".')
condition: string?
@description('Optional. Version of the condition.')
conditionVersion: '2.0'?
@description('Optional. The Resource Id of the delegated managed identity resource.')
delegatedManagedIdentityResourceId: string?
}[]?
type networkAclsType = {
@description('Optional. Sets the resource access rules. Array entries must consist of "tenantId" and "resourceId" fields only.')
resourceAccessRules: {
@description('Required. The ID of the tenant in which the resource resides in.')
tenantId: string
@description('Required. The resource ID of the target service. Can also contain a wildcard, if multiple services e.g. in a resource group should be included.')
resourceId: string
}[]?
@description('Optional. Specifies whether traffic is bypassed for Logging/Metrics/AzureServices. Possible values are any combination of Logging,Metrics,AzureServices (For example, "Logging, Metrics"), or None to bypass none of those traffics.')
bypass: (
| 'None'
| 'AzureServices'
| 'Logging'
| 'Metrics'
| 'AzureServices, Logging'
| 'AzureServices, Metrics'
| 'AzureServices, Logging, Metrics'
| 'Logging, Metrics')?
@description('Optional. Sets the virtual network rules.')
virtualNetworkRules: array?
@description('Optional. Sets the IP ACL rules.')
ipRules: array?
@description('Optional. Specifies the default action of allow or deny when no other rules match.')
defaultAction: ('Allow' | 'Deny')?
}
type privateEndpointType = {
@description('Optional. The name of the private endpoint.')
name: string?
@description('Optional. The location to deploy the private endpoint to.')
location: string?
@description('Optional. The name of the private link connection to create.')
privateLinkServiceConnectionName: string?
@description('Required. The subresource to deploy the private endpoint for. For example "blob", "table", "queue" or "file".')
service: string
@description('Required. Resource ID of the subnet where the endpoint needs to be created.')
subnetResourceId: string
@description('Optional. The name of the private DNS zone group to create if privateDnsZoneResourceIds were provided.')
privateDnsZoneGroupName: string?
@description('Optional. The private DNS zone groups to associate the private endpoint with. A DNS zone group can support up to 5 DNS zones.')
privateDnsZoneResourceIds: string[]?
@description('Optional. If Manual Private Link Connection is required.')
isManualConnection: bool?
@description('Optional. A message passed to the owner of the remote resource with the manual connection request.')
@maxLength(140)
manualConnectionRequestMessage: string?
@description('Optional. Custom DNS configurations.')
customDnsConfigs: {
@description('Required. Fqdn that resolves to private endpoint ip address.')
fqdn: string?
@description('Required. A list of private ip addresses of the private endpoint.')
ipAddresses: string[]
}[]?
@description('Optional. A list of IP configurations of the private endpoint. This will be used to map to the First Party Service endpoints.')
ipConfigurations: {
@description('Required. The name of the resource that is unique within a resource group.')
name: string
@description('Required. Properties of private endpoint IP configurations.')
properties: {
@description('Required. The ID of a group obtained from the remote resource that this private endpoint should connect to.')
groupId: string
@description('Required. The member name of a group obtained from the remote resource that this private endpoint should connect to.')
memberName: string
@description('Required. A private ip address obtained from the private endpoint\'s subnet.')
privateIPAddress: string
}
}[]?
@description('Optional. Application security groups in which the private endpoint IP configuration is included.')
applicationSecurityGroupResourceIds: string[]?
@description('Optional. The custom name of the network interface attached to the private endpoint.')
customNetworkInterfaceName: string?
@description('Optional. Specify the type of lock.')
lock: lockType
@description('Optional. Array of role assignments to create.')
roleAssignments: roleAssignmentType
@description('Optional. Tags to be applied on all resources/resource groups in this deployment.')
tags: object?
@description('Optional. Enable/Disable usage telemetry for module.')
enableTelemetry: bool?
@description('Optional. Specify if you want to deploy the Private Endpoint into a different resource group than the main resource.')
resourceGroupName: string?
}[]?
type diagnosticSettingType = {
@description('Optional. The name of diagnostic setting.')
name: string?
@description('Optional. The name of logs that will be streamed. "allLogs" includes all possible logs for the resource. Set to `[]` to disable log collection.')
metricCategories: {
@description('Required. Name of a Diagnostic Metric category for a resource type this setting is applied to. Set to `AllMetrics` to collect all metrics.')
category: string
@description('Optional. Enable or disable the category explicitly. Default is `true`.')
enabled: bool?
}[]?
@description('Optional. A string indicating whether the export to Log Analytics should use the default destination type, i.e. AzureDiagnostics, or use a destination type.')
logAnalyticsDestinationType: ('Dedicated' | 'AzureDiagnostics')?
@description('Optional. Resource ID of the diagnostic log analytics workspace. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
workspaceResourceId: string?
@description('Optional. Resource ID of the diagnostic storage account. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
storageAccountResourceId: string?
@description('Optional. Resource ID of the diagnostic event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to.')
eventHubAuthorizationRuleResourceId: string?
@description('Optional. Name of the diagnostic event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
eventHubName: string?
@description('Optional. The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic Logs.')
marketplacePartnerResourceId: string?
}[]?
type customerManagedKeyType = {
@description('Required. The resource ID of a key vault to reference a customer managed key for encryption from.')
keyVaultResourceId: string
@description('Required. The name of the customer managed key to use for encryption.')
keyName: string
@description('Optional. The version of the customer managed key to reference for encryption. If not provided, using \'latest\'.')
keyVersion: string?
@description('Optional. User assigned identity to use when fetching the customer managed key. If used must also be specified in `managedIdentities.userAssignedResourceIds`. Required if no system assigned identity is available for use.')
userAssignedIdentityResourceId: string?
}?