|
| 1 | +// Parameters |
| 2 | +@description('Specifies the name of the Azure Cosmos DB resource') |
| 3 | +param name string |
| 4 | + |
| 5 | +@description('Specifies the primary location of Azure resources.') |
| 6 | +param location string = resourceGroup().location |
| 7 | + |
| 8 | +@description('Specifies the resource tags.') |
| 9 | +param tags object = {} |
| 10 | + |
| 11 | +@description('Specifies the name of the Azure Cosmos DB account name, max length 44 characters, lowercase.') |
| 12 | +param accountName string = toLower('${name}account') |
| 13 | + |
| 14 | +@description('The primary region for the Cosmos DB account.') |
| 15 | +param primaryRegion string |
| 16 | + |
| 17 | +@description('The secondary region for the Cosmos DB account.') |
| 18 | +param secondaryRegion string |
| 19 | + |
| 20 | +@description('The default consistency level of the Cosmos DB account.') |
| 21 | +@allowed([ |
| 22 | + 'Eventual' |
| 23 | + 'ConsistentPrefix' |
| 24 | + 'Session' |
| 25 | + 'BoundedStaleness' |
| 26 | + 'Strong' |
| 27 | +]) |
| 28 | +param defaultConsistencyLevel string = 'Session' |
| 29 | + |
| 30 | +@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.') |
| 31 | +@minValue(10) |
| 32 | +@maxValue(2147483647) |
| 33 | +param maxStalenessPrefix int = 100000 |
| 34 | + |
| 35 | +@description('Max lag time (minutes). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.') |
| 36 | +@minValue(5) |
| 37 | +@maxValue(86400) |
| 38 | +param maxIntervalInSeconds int = 300 |
| 39 | + |
| 40 | +@description('Enable system managed failover for regions') |
| 41 | +param systemManagedFailover bool = true |
| 42 | + |
| 43 | +var consistencyPolicy = { |
| 44 | + Eventual: { |
| 45 | + defaultConsistencyLevel: 'Eventual' |
| 46 | + } |
| 47 | + ConsistentPrefix: { |
| 48 | + defaultConsistencyLevel: 'ConsistentPrefix' |
| 49 | + } |
| 50 | + Session: { |
| 51 | + defaultConsistencyLevel: 'Session' |
| 52 | + } |
| 53 | + BoundedStaleness: { |
| 54 | + defaultConsistencyLevel: 'BoundedStaleness' |
| 55 | + maxStalenessPrefix: maxStalenessPrefix |
| 56 | + maxIntervalInSeconds: maxIntervalInSeconds |
| 57 | + } |
| 58 | + Strong: { |
| 59 | + defaultConsistencyLevel: 'Strong' |
| 60 | + } |
| 61 | +} |
| 62 | +var locations = [ |
| 63 | + { |
| 64 | + locationName: primaryRegion |
| 65 | + failoverPriority: 0 |
| 66 | + isZoneRedundant: false |
| 67 | + } |
| 68 | + { |
| 69 | + locationName: secondaryRegion |
| 70 | + failoverPriority: 1 |
| 71 | + isZoneRedundant: false |
| 72 | + } |
| 73 | +] |
| 74 | + |
| 75 | +resource account 'Microsoft.DocumentDB/databaseAccounts@2024-02-15-preview' = { |
| 76 | + name: accountName |
| 77 | + location: location |
| 78 | + tags: tags |
| 79 | + kind: 'GlobalDocumentDB' |
| 80 | + properties: { |
| 81 | + consistencyPolicy: consistencyPolicy[defaultConsistencyLevel] |
| 82 | + locations: locations |
| 83 | + databaseAccountOfferType: 'Standard' |
| 84 | + enableAutomaticFailover: systemManagedFailover |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +// Outputs |
| 89 | +output accountId string = account.id |
| 90 | +output accountName string = account.name |
| 91 | +output accountEndpoint string = account.properties.documentEndpoint |
0 commit comments