|
| 1 | +metadata description = 'Creates an Azure storage account.' |
| 2 | +param name string |
| 3 | +param location string = resourceGroup().location |
| 4 | +param tags object = {} |
| 5 | + |
| 6 | +@allowed([ |
| 7 | + 'Cool' |
| 8 | + 'Hot' |
| 9 | + 'Premium' ]) |
| 10 | +param accessTier string = 'Hot' |
| 11 | +param allowBlobPublicAccess bool = true |
| 12 | +param allowCrossTenantReplication bool = true |
| 13 | +param allowSharedKeyAccess bool = true |
| 14 | +param containers array = [] |
| 15 | +param corsRules array = [] |
| 16 | +param defaultToOAuthAuthentication bool = false |
| 17 | +param deleteRetentionPolicy object = {} |
| 18 | +@allowed([ 'AzureDnsZone', 'Standard' ]) |
| 19 | +param dnsEndpointType string = 'Standard' |
| 20 | +param files array = [] |
| 21 | +param kind string = 'StorageV2' |
| 22 | +param minimumTlsVersion string = 'TLS1_2' |
| 23 | +param queues array = [] |
| 24 | +param shareDeleteRetentionPolicy object = {} |
| 25 | +param supportsHttpsTrafficOnly bool = true |
| 26 | +param tables array = [] |
| 27 | +param networkAcls object = { |
| 28 | + bypass: 'AzureServices' |
| 29 | + defaultAction: 'Allow' |
| 30 | +} |
| 31 | +@allowed([ 'Enabled', 'Disabled' ]) |
| 32 | +param publicNetworkAccess string = 'Enabled' |
| 33 | +param sku object = { name: 'Standard_LRS' } |
| 34 | +param keyVaultName string = '' |
| 35 | + |
| 36 | +resource storage 'Microsoft.Storage/storageAccounts@2023-01-01' = { |
| 37 | + name: name |
| 38 | + location: location |
| 39 | + tags: tags |
| 40 | + kind: kind |
| 41 | + sku: sku |
| 42 | + properties: { |
| 43 | + accessTier: accessTier |
| 44 | + allowBlobPublicAccess: allowBlobPublicAccess |
| 45 | + allowCrossTenantReplication: allowCrossTenantReplication |
| 46 | + allowSharedKeyAccess: allowSharedKeyAccess |
| 47 | + defaultToOAuthAuthentication: defaultToOAuthAuthentication |
| 48 | + dnsEndpointType: dnsEndpointType |
| 49 | + minimumTlsVersion: minimumTlsVersion |
| 50 | + networkAcls: networkAcls |
| 51 | + publicNetworkAccess: publicNetworkAccess |
| 52 | + supportsHttpsTrafficOnly: supportsHttpsTrafficOnly |
| 53 | + } |
| 54 | + |
| 55 | + resource blobServices 'blobServices' = if (!empty(containers)) { |
| 56 | + name: 'default' |
| 57 | + properties: { |
| 58 | + cors: { |
| 59 | + corsRules: corsRules |
| 60 | + } |
| 61 | + deleteRetentionPolicy: deleteRetentionPolicy |
| 62 | + } |
| 63 | + resource container 'containers' = [for container in containers: { |
| 64 | + name: container.name |
| 65 | + properties: { |
| 66 | + // todo: Warning use-safe-access: Use the safe access (.?) operator instead of checking object contents with the 'contains' function. [https://aka.ms/bicep/linter/use-safe-access] |
| 67 | + publicAccess: contains(container, 'publicAccess') ? container.publicAccess : 'None' |
| 68 | + } |
| 69 | + }] |
| 70 | + } |
| 71 | + |
| 72 | + resource fileServices 'fileServices' = if (!empty(files)) { |
| 73 | + name: 'default' |
| 74 | + properties: { |
| 75 | + cors: { |
| 76 | + corsRules: corsRules |
| 77 | + } |
| 78 | + shareDeleteRetentionPolicy: shareDeleteRetentionPolicy |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + resource queueServices 'queueServices' = if (!empty(queues)) { |
| 83 | + name: 'default' |
| 84 | + properties: { |
| 85 | + |
| 86 | + } |
| 87 | + resource queue 'queues' = [for queue in queues: { |
| 88 | + name: queue.name |
| 89 | + properties: { |
| 90 | + metadata: {} |
| 91 | + } |
| 92 | + }] |
| 93 | + } |
| 94 | + |
| 95 | + resource tableServices 'tableServices' = if (!empty(tables)) { |
| 96 | + name: 'default' |
| 97 | + properties: {} |
| 98 | + // create tables pre-defined in aspire.bicep |
| 99 | + resource table 'tables' = [for table in tables: { |
| 100 | + name: table |
| 101 | + properties: {} |
| 102 | + }] |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +// Save Storage Account Connection String in Key Vault Secret |
| 107 | +module keyVaultSecrets '../../core/security/keyvault-secret.bicep' = { |
| 108 | + name: 'keyVaultSecrets' |
| 109 | + params: { |
| 110 | + name: 'storage-connection-string' |
| 111 | + secretValue:'DefaultEndpointsProtocol=https;EndpointSuffix=${environment().suffixes.storage};AccountName=${storage.name};AccountKey=${storage.listKeys().keys[0].value};BlobEndpoint=${storage.properties.primaryEndpoints.blob};FileEndpoint=${storage.properties.primaryEndpoints.file};QueueEndpoint=${storage.properties.primaryEndpoints.queue};TableEndpoint=${storage.properties.primaryEndpoints.table}' |
| 112 | + keyVaultName:keyVaultName |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +output id string = storage.id |
| 117 | +output name string = storage.name |
| 118 | +output primaryEndpoints object = storage.properties.primaryEndpoints |
0 commit comments