|
| 1 | +@description('Azure Cosmos DB account name, max length 44 characters') |
| 2 | +param accountName string = uniqueString('cosmos', resourceGroup().id) |
| 3 | + |
| 4 | +@description('Location for the Azure Cosmos DB account.') |
| 5 | +param location string = resourceGroup().location |
| 6 | + |
| 7 | +@allowed([ |
| 8 | + 'Eventual' |
| 9 | + 'ConsistentPrefix' |
| 10 | + 'Session' |
| 11 | + 'BoundedStaleness' |
| 12 | + 'Strong' |
| 13 | +]) |
| 14 | +@description('The default consistency level of the Cosmos DB account.') |
| 15 | +param defaultConsistencyLevel string = 'Session' |
| 16 | + |
| 17 | +@minValue(10) |
| 18 | +@maxValue(2147483647) |
| 19 | +@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.') |
| 20 | +param maxStalenessPrefix int = 100000 |
| 21 | + |
| 22 | +@minValue(5) |
| 23 | +@maxValue(86400) |
| 24 | +@description('Max lag time (minutes). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.') |
| 25 | +param maxIntervalInSeconds int = 300 |
| 26 | + |
| 27 | +@allowed([ |
| 28 | + true |
| 29 | + false |
| 30 | +]) |
| 31 | +@description('Enable system managed failover for regions') |
| 32 | +param systemManagedFailover bool = false |
| 33 | + |
| 34 | +@description('The name for the database') |
| 35 | +param databaseName string = 'myDatabase' |
| 36 | + |
| 37 | +@description('The name for the input container') |
| 38 | +param inContainerName string = 'myContainer' |
| 39 | + |
| 40 | +@description('The name for the output container') |
| 41 | +param outContainerName string = 'yourContainer' |
| 42 | + |
| 43 | +@minValue(400) |
| 44 | +@maxValue(1000000) |
| 45 | +@description('The throughput for the container') |
| 46 | +param throughput int = 400 |
| 47 | + |
| 48 | +var consistencyPolicy = { |
| 49 | + Eventual: { |
| 50 | + defaultConsistencyLevel: 'Eventual' |
| 51 | + } |
| 52 | + ConsistentPrefix: { |
| 53 | + defaultConsistencyLevel: 'ConsistentPrefix' |
| 54 | + } |
| 55 | + Session: { |
| 56 | + defaultConsistencyLevel: 'Session' |
| 57 | + } |
| 58 | + BoundedStaleness: { |
| 59 | + defaultConsistencyLevel: 'BoundedStaleness' |
| 60 | + maxStalenessPrefix: maxStalenessPrefix |
| 61 | + maxIntervalInSeconds: maxIntervalInSeconds |
| 62 | + } |
| 63 | + Strong: { |
| 64 | + defaultConsistencyLevel: 'Strong' |
| 65 | + } |
| 66 | +} |
| 67 | +var locations = [ |
| 68 | + { |
| 69 | + locationName: location |
| 70 | + failoverPriority: 0 |
| 71 | + isZoneRedundant: false |
| 72 | + } |
| 73 | +] |
| 74 | + |
| 75 | +resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = { |
| 76 | + name: toLower(accountName) |
| 77 | + location: location |
| 78 | + kind: 'GlobalDocumentDB' |
| 79 | + properties: { |
| 80 | + consistencyPolicy: consistencyPolicy[defaultConsistencyLevel] |
| 81 | + locations: locations |
| 82 | + databaseAccountOfferType: 'Standard' |
| 83 | + enableAutomaticFailover: systemManagedFailover |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +resource database 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = { |
| 88 | + name: '${account.name}/${databaseName}' |
| 89 | + properties: { |
| 90 | + resource: { |
| 91 | + id: databaseName |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +resource container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-05-15' = { |
| 97 | + name: '${database.name}/${inContainerName}' |
| 98 | + properties: { |
| 99 | + resource: { |
| 100 | + id: inContainerName |
| 101 | + partitionKey: { |
| 102 | + paths: [ |
| 103 | + '/country' |
| 104 | + ] |
| 105 | + kind: 'Hash' |
| 106 | + } |
| 107 | + indexingPolicy: { |
| 108 | + indexingMode: 'consistent' |
| 109 | + automatic: true |
| 110 | + includedPaths: [ |
| 111 | + { |
| 112 | + path: '/*' |
| 113 | + } |
| 114 | + ] |
| 115 | + excludedPaths: [ |
| 116 | + { |
| 117 | + path: '/\'_etag\'/?' |
| 118 | + } |
| 119 | + ] |
| 120 | + } |
| 121 | + defaultTtl: 86400 |
| 122 | + } |
| 123 | + options: { |
| 124 | + throughput: throughput |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +resource container2 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-05-15' = { |
| 130 | + name: '${database.name}/${outContainerName}' |
| 131 | + properties: { |
| 132 | + resource: { |
| 133 | + id: outContainerName |
| 134 | + partitionKey: { |
| 135 | + paths: [ |
| 136 | + '/country' |
| 137 | + ] |
| 138 | + kind: 'Hash' |
| 139 | + } |
| 140 | + indexingPolicy: { |
| 141 | + indexingMode: 'consistent' |
| 142 | + automatic: true |
| 143 | + includedPaths: [ |
| 144 | + { |
| 145 | + path: '/*' |
| 146 | + } |
| 147 | + ] |
| 148 | + excludedPaths: [ |
| 149 | + { |
| 150 | + path: '/\'_etag\'/?' |
| 151 | + } |
| 152 | + ] |
| 153 | + } |
| 154 | + defaultTtl: 86400 |
| 155 | + } |
| 156 | + options: { |
| 157 | + throughput: throughput |
| 158 | + } |
| 159 | + } |
| 160 | +} |
0 commit comments