Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add a possibility to specify partition key version for Hash partition key type #1921

Merged
merged 13 commits into from
May 22, 2024
31 changes: 31 additions & 0 deletions avm/res/document-db/database-account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,14 @@ module databaseAccount 'br/public:avm/res/document-db/database-account:<version>
'myPartitionKey1'
]
}
{
kind: 'Hash'
name: 'container-005'
paths: [
'myPartitionKey1'
]
version: 2
}
]
name: 'all-partition-key-types'
}
Expand Down Expand Up @@ -2020,6 +2028,14 @@ module databaseAccount 'br/public:avm/res/document-db/database-account:<version>
"paths": [
"myPartitionKey1"
]
},
{
"kind": "Hash",
"name": "container-005",
"paths": [
"myPartitionKey1"
],
"version": 2
}
],
"name": "all-partition-key-types"
Expand Down Expand Up @@ -3384,6 +3400,7 @@ Array of containers to deploy in the SQL database.
| [`kind`](#parameter-sqldatabasescontainerskind) | string | Default to Hash. Indicates the kind of algorithm used for partitioning. |
| [`throughput`](#parameter-sqldatabasescontainersthroughput) | int | Default to 400. Request Units per second. Will be ignored if autoscaleSettingsMaxThroughput is used. |
| [`uniqueKeyPolicyKeys`](#parameter-sqldatabasescontainersuniquekeypolicykeys) | array | The unique key policy configuration containing a list of unique keys that enforces uniqueness constraint on documents in the collection in the Azure Cosmos DB service. |
| [`version`](#parameter-sqldatabasescontainersversion) | int | Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition. |

### Parameter: `sqlDatabases.containers.name`

Expand Down Expand Up @@ -3516,6 +3533,20 @@ List of paths must be unique for each document in the Azure Cosmos DB service.
- Required: Yes
- Type: array

### Parameter: `sqlDatabases.containers.version`

Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition.

- Required: No
- Type: int
- Allowed:
```Bicep
[
1
2
]
```

### Parameter: `sqlDatabases.throughput`

Default to 400. Request units per second. Will be ignored if autoscaleSettingsMaxThroughput is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "2823004405398378621"
"version": "0.27.1.19265",
"templateHash": "3987394297554402770"
},
"name": "DocumentDB Database Accounts Gremlin Databases Graphs",
"description": "This module deploys a DocumentDB Database Accounts Gremlin Database Graph.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "13414524346849431368"
"version": "0.27.1.19265",
"templateHash": "6889435067791947905"
},
"name": "DocumentDB Database Account Gremlin Databases",
"description": "This module deploys a Gremlin Database within a CosmosDB Account.",
Expand Down Expand Up @@ -109,8 +109,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "2823004405398378621"
"version": "0.27.1.19265",
"templateHash": "3987394297554402770"
},
"name": "DocumentDB Database Accounts Gremlin Databases Graphs",
"description": "This module deploys a DocumentDB Database Accounts Gremlin Database Graph.",
Expand Down
3 changes: 3 additions & 0 deletions avm/res/document-db/database-account/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,9 @@ type sqlDatabaseType = {
@description('Optional. Default to Hash. Indicates the kind of algorithm used for partitioning.')
kind: ('Hash' | 'MultiHash')?

@description('Optional. Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition.')
version: (1 | 2)?

@description('Optional. Default to 400. Request Units per second. Will be ignored if autoscaleSettingsMaxThroughput is used.')
throughput: int?

Expand Down
36 changes: 30 additions & 6 deletions avm/res/document-db/database-account/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.27.1.19265",
"templateHash": "8399904898851436683"
"templateHash": "5516885052191994610"
},
"name": "DocumentDB Database Accounts",
"description": "This module deploys a DocumentDB Database Account.",
Expand Down Expand Up @@ -587,6 +587,17 @@
"description": "Optional. Default to Hash. Indicates the kind of algorithm used for partitioning."
}
},
"version": {
"type": "int",
"allowedValues": [
1,
2
],
"nullable": true,
"metadata": {
"description": "Optional. Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition."
}
},
"throughput": {
"type": "int",
"nullable": true,
Expand Down Expand Up @@ -1250,7 +1261,7 @@
"_generator": {
"name": "bicep",
"version": "0.27.1.19265",
"templateHash": "15534269553484112693"
"templateHash": "8319829662998768775"
},
"name": "DocumentDB Database Account SQL Databases",
"description": "This module deploys a SQL Database in a CosmosDB Account.",
Expand Down Expand Up @@ -1364,6 +1375,9 @@
"kind": {
"value": "[tryGet(parameters('containers')[copyIndex()], 'kind')]"
},
"version": {
"value": "[tryGet(parameters('containers')[copyIndex()], 'version')]"
},
"paths": {
"value": "[tryGet(parameters('containers')[copyIndex()], 'paths')]"
},
Expand All @@ -1380,7 +1394,7 @@
"_generator": {
"name": "bicep",
"version": "0.27.1.19265",
"templateHash": "12755071159425783033"
"templateHash": "3824205620211058652"
},
"name": "DocumentDB Database Account SQL Database Containers",
"description": "This module deploys a SQL Database Container in a CosmosDB Account.",
Expand Down Expand Up @@ -1480,12 +1494,22 @@
"defaultValue": "Hash",
"allowedValues": [
"Hash",
"MultiHash",
"Range"
"MultiHash"
],
"metadata": {
"description": "Optional. Default to Hash. Indicates the kind of algorithm used for partitioning."
}
},
"version": {
"type": "int",
"defaultValue": 1,
"allowedValues": [
1,
2
],
"metadata": {
"description": "Optional. Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition."
}
}
},
"variables": {
Expand All @@ -1496,7 +1520,7 @@
"input": "[if(startsWith(parameters('paths')[copyIndex('partitionKeyPaths')], '/'), parameters('paths')[copyIndex('partitionKeyPaths')], format('/{0}', parameters('paths')[copyIndex('partitionKeyPaths')]))]"
}
],
"containerResourceParams": "[union(createObject('conflictResolutionPolicy', parameters('conflictResolutionPolicy'), 'defaultTtl', parameters('defaultTtl'), 'id', parameters('name'), 'indexingPolicy', if(not(empty(parameters('indexingPolicy'))), parameters('indexingPolicy'), null()), 'partitionKey', createObject('paths', variables('partitionKeyPaths'), 'kind', parameters('kind'), 'version', if(equals(parameters('kind'), 'MultiHash'), 2, 1)), 'uniqueKeyPolicy', if(not(empty(parameters('uniqueKeyPolicyKeys'))), createObject('uniqueKeys', parameters('uniqueKeyPolicyKeys')), null())), if(not(equals(parameters('analyticalStorageTtl'), 0)), createObject('analyticalStorageTtl', parameters('analyticalStorageTtl')), createObject()))]"
"containerResourceParams": "[union(createObject('conflictResolutionPolicy', parameters('conflictResolutionPolicy'), 'defaultTtl', parameters('defaultTtl'), 'id', parameters('name'), 'indexingPolicy', if(not(empty(parameters('indexingPolicy'))), parameters('indexingPolicy'), null()), 'partitionKey', createObject('paths', variables('partitionKeyPaths'), 'kind', parameters('kind'), 'version', if(equals(parameters('kind'), 'MultiHash'), 2, parameters('version'))), 'uniqueKeyPolicy', if(not(empty(parameters('uniqueKeyPolicyKeys'))), createObject('uniqueKeys', parameters('uniqueKeyPolicyKeys')), null())), if(not(equals(parameters('analyticalStorageTtl'), 0)), createObject('analyticalStorageTtl', parameters('analyticalStorageTtl')), createObject()))]"
},
"resources": {
"databaseAccount::sqlDatabase": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "1989910090472113779"
"version": "0.27.1.19265",
"templateHash": "6235322895830297683"
},
"name": "DocumentDB Database Account MongoDB Database Collections",
"description": "This module deploys a MongoDB Database Collection.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "7706794569430424680"
"version": "0.27.1.19265",
"templateHash": "1527748615955553712"
},
"name": "DocumentDB Database Account MongoDB Databases",
"description": "This module deploys a MongoDB Database within a CosmosDB Account.",
Expand Down Expand Up @@ -108,8 +108,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "1989910090472113779"
"version": "0.27.1.19265",
"templateHash": "6235322895830297683"
},
"name": "DocumentDB Database Account MongoDB Database Collections",
"description": "This module deploys a MongoDB Database Collection.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This module deploys a SQL Database Container in a CosmosDB Account.
| [`tags`](#parameter-tags) | object | Tags of the SQL Database resource. |
| [`throughput`](#parameter-throughput) | int | Default to 400. Request Units per second. Will be ignored if autoscaleSettingsMaxThroughput is used. |
| [`uniqueKeyPolicyKeys`](#parameter-uniquekeypolicykeys) | array | The unique key policy configuration containing a list of unique keys that enforces uniqueness constraint on documents in the collection in the Azure Cosmos DB service. |
| [`version`](#parameter-version) | int | Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition. |

### Parameter: `name`

Expand Down Expand Up @@ -126,7 +127,6 @@ Default to Hash. Indicates the kind of algorithm used for partitioning.
[
'Hash'
'MultiHash'
'Range'
]
```

Expand All @@ -153,6 +153,21 @@ The unique key policy configuration containing a list of unique keys that enforc
- Type: array
- Default: `[]`

### Parameter: `version`

Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition.

- Required: No
- Type: int
- Default: `1`
- Allowed:
```Bicep
[
1
2
]
```


## Outputs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ param uniqueKeyPolicyKeys array = []
@allowed([
'Hash'
'MultiHash'
'Range'
])
param kind string = 'Hash'
@description('Optional. Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition.')
@allowed([1, 2])
param version int = 1

var partitionKeyPaths = [for path in paths: startsWith(path, '/') ? path : '/${path}']

Expand All @@ -62,7 +64,7 @@ var containerResourceParams = union(
partitionKey: {
paths: partitionKeyPaths
kind: kind
version: kind == 'MultiHash' ? 2 : 1
version: kind == 'MultiHash' ? 2 : version
}
uniqueKeyPolicy: !empty(uniqueKeyPolicyKeys)
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "11250469246171251281"
"version": "0.27.1.19265",
"templateHash": "3824205620211058652"
},
"name": "DocumentDB Database Account SQL Database Containers",
"description": "This module deploys a SQL Database Container in a CosmosDB Account.",
Expand Down Expand Up @@ -106,12 +106,22 @@
"defaultValue": "Hash",
"allowedValues": [
"Hash",
"MultiHash",
"Range"
"MultiHash"
],
"metadata": {
"description": "Optional. Default to Hash. Indicates the kind of algorithm used for partitioning."
}
},
"version": {
"type": "int",
"defaultValue": 1,
"allowedValues": [
1,
2
],
"metadata": {
"description": "Optional. Default to 1 for Hash and 2 for MultiHash - 1 is not allowed for MultiHash. Version of the partition key definition."
}
}
},
"variables": {
Expand All @@ -122,7 +132,7 @@
"input": "[if(startsWith(parameters('paths')[copyIndex('partitionKeyPaths')], '/'), parameters('paths')[copyIndex('partitionKeyPaths')], format('/{0}', parameters('paths')[copyIndex('partitionKeyPaths')]))]"
}
],
"containerResourceParams": "[union(createObject('conflictResolutionPolicy', parameters('conflictResolutionPolicy'), 'defaultTtl', parameters('defaultTtl'), 'id', parameters('name'), 'indexingPolicy', if(not(empty(parameters('indexingPolicy'))), parameters('indexingPolicy'), null()), 'partitionKey', createObject('paths', variables('partitionKeyPaths'), 'kind', parameters('kind'), 'version', if(equals(parameters('kind'), 'MultiHash'), 2, 1)), 'uniqueKeyPolicy', if(not(empty(parameters('uniqueKeyPolicyKeys'))), createObject('uniqueKeys', parameters('uniqueKeyPolicyKeys')), null())), if(not(equals(parameters('analyticalStorageTtl'), 0)), createObject('analyticalStorageTtl', parameters('analyticalStorageTtl')), createObject()))]"
"containerResourceParams": "[union(createObject('conflictResolutionPolicy', parameters('conflictResolutionPolicy'), 'defaultTtl', parameters('defaultTtl'), 'id', parameters('name'), 'indexingPolicy', if(not(empty(parameters('indexingPolicy'))), parameters('indexingPolicy'), null()), 'partitionKey', createObject('paths', variables('partitionKeyPaths'), 'kind', parameters('kind'), 'version', if(equals(parameters('kind'), 'MultiHash'), 2, parameters('version'))), 'uniqueKeyPolicy', if(not(empty(parameters('uniqueKeyPolicyKeys'))), createObject('uniqueKeys', parameters('uniqueKeyPolicyKeys')), null())), if(not(equals(parameters('analyticalStorageTtl'), 0)), createObject('analyticalStorageTtl', parameters('analyticalStorageTtl')), createObject()))]"
},
"resources": {
"databaseAccount::sqlDatabase": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module container 'container/main.bicep' = [
defaultTtl: container.?defaultTtl
indexingPolicy: container.?indexingPolicy
kind: container.?kind
version: container.?version
paths: container.?paths
throughput: (throughput != null || autoscaleSettingsMaxThroughput != null) && container.?throughput == null
? -1
Expand Down
Loading
Loading