|
| 1 | +param baseName string |
| 2 | + |
| 3 | +@description('Flag to enable or disable multiple write locations on CosmosDB Account') |
| 4 | +param enableMultipleWriteLocations bool |
| 5 | + |
| 6 | +@description('Default Cosmosdb Account level consistency') |
| 7 | +param defaultConsistencyLevel string = 'Session' |
| 8 | + |
| 9 | +@description('Enable multiple regions, default value is false') |
| 10 | +param enableMultipleRegions bool = false |
| 11 | + |
| 12 | +@description('Location for the Cosmos DB account.') |
| 13 | +param location string = resourceGroup().location |
| 14 | + |
| 15 | +@description('The api version to be used by Bicep to create resources') |
| 16 | +param apiVersion string = '2020-04-01' |
| 17 | + |
| 18 | +var accountName = toLower(baseName) |
| 19 | +var resourceId = cosmosAccount.id |
| 20 | +var singleRegionConfiguration = [ |
| 21 | + { |
| 22 | + locationName: 'East US 2' |
| 23 | + provisioningState: 'Succeeded' |
| 24 | + failoverPriority: 0 |
| 25 | + isZoneRedundant: false |
| 26 | + } |
| 27 | +] |
| 28 | +var multiRegionConfiguration = [ |
| 29 | + { |
| 30 | + locationName: 'East US 2' |
| 31 | + provisioningState: 'Succeeded' |
| 32 | + failoverPriority: 0 |
| 33 | + isZoneRedundant: false |
| 34 | + } |
| 35 | + { |
| 36 | + locationName: 'East US' |
| 37 | + provisioningState: 'Succeeded' |
| 38 | + failoverPriority: 1 |
| 39 | + isZoneRedundant: false |
| 40 | + } |
| 41 | +] |
| 42 | +var locationsConfiguration = (enableMultipleRegions ? multiRegionConfiguration : singleRegionConfiguration) |
| 43 | + |
| 44 | +resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2020-04-01' = { |
| 45 | + name: toLower(accountName) |
| 46 | + location: location |
| 47 | + kind: 'GlobalDocumentDB' |
| 48 | + properties: { |
| 49 | + publicNetworkAccess: 'Enabled' |
| 50 | + enableAutomaticFailover: false |
| 51 | + enableMultipleWriteLocations: enableMultipleWriteLocations |
| 52 | + isVirtualNetworkFilterEnabled: false |
| 53 | + disableKeyBasedMetadataWriteAccess: false |
| 54 | + enableFreeTier: false |
| 55 | + enableAnalyticalStorage: false |
| 56 | + databaseAccountOfferType: 'Standard' |
| 57 | + consistencyPolicy: { |
| 58 | + defaultConsistencyLevel: defaultConsistencyLevel |
| 59 | + } |
| 60 | + locations: locationsConfiguration |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +output ACCOUNT_HOST string = reference(resourceId, apiVersion).documentEndpoint |
| 66 | +output ACCOUNT_KEY string = listKeys(resourceId, apiVersion).primaryMasterKey |
0 commit comments