From d9ffe275d5c2d4bd46a4bad4b2d255bb2443243a Mon Sep 17 00:00:00 2001 From: "Axel B. Andersen" Date: Wed, 22 May 2024 16:18:56 +0200 Subject: [PATCH] [Feature Request] Add a possibility to specify partition key version for Hash partition key type (#1921) ## Description SQL database container defaults to 2 if omitted. This fixes that issue Fixes #1852 (closed by accident) ## Pipeline Reference | Pipeline | | -------- | |[![avm.res.document-db.database-account](https://github.com/Agazoth/bicep-registry-modules/actions/workflows/avm.res.document-db.database-account.yml/badge.svg?branch=DocumentDBDefaultForHash)](https://github.com/Agazoth/bicep-registry-modules/actions/workflows/avm.res.document-db.database-account.yml)| ## Type of Change - [ ] Update to CI Environment or utlities (Non-module effecting changes) - [ ] Azure Verified Module updates: - [x] Bugfix containing backwards compatible bug fixes, and I have NOT bumped the MAJOR or MINOR version in `version.json`: - [ ] Someone has opened a bug report issue, and I have included "Closes #{bug_report_issue_number}" in the PR description. - [ ] The bug was found by the module author, and no one has opened an issue to report it yet. - [ ] Feature update backwards compatible feature updates, and I have bumped the MINOR version in `version.json`. - [ ] Breaking changes and I have bumped the MAJOR version in `version.json`. - [ ] Update to documentation ## Checklist - [x] I'm sure there are no other open Pull Requests for the same update/change - [x] I have run `Set-AVMModule` locally to generate the supporting module files. - [x] My corresponding pipelines / checks run clean and green without any errors or warnings --------- Co-authored-by: Bryan <117635118+bryansan-msft@users.noreply.github.com> --- .../document-db/database-account/README.md | 31 ++++++++++++++++ .../gremlin-database/graph/main.json | 4 +-- .../gremlin-database/main.json | 8 ++--- .../document-db/database-account/main.bicep | 3 ++ .../document-db/database-account/main.json | 36 +++++++++++++++---- .../mongodb-database/collection/main.json | 4 +-- .../mongodb-database/main.json | 8 ++--- .../sql-database/container/README.md | 17 ++++++++- .../sql-database/container/main.bicep | 6 ++-- .../sql-database/container/main.json | 20 ++++++++--- .../database-account/sql-database/main.bicep | 1 + .../database-account/sql-database/main.json | 27 ++++++++++---- .../tests/e2e/sqldb/main.test.bicep | 8 +++++ 13 files changed, 140 insertions(+), 33 deletions(-) diff --git a/avm/res/document-db/database-account/README.md b/avm/res/document-db/database-account/README.md index 73c60b1d9b..e381d85ccd 100644 --- a/avm/res/document-db/database-account/README.md +++ b/avm/res/document-db/database-account/README.md @@ -1742,6 +1742,14 @@ module databaseAccount 'br/public:avm/res/document-db/database-account: 'myPartitionKey1' ] } + { + kind: 'Hash' + name: 'container-005' + paths: [ + 'myPartitionKey1' + ] + version: 2 + } ] name: 'all-partition-key-types' } @@ -2020,6 +2028,14 @@ module databaseAccount 'br/public:avm/res/document-db/database-account: "paths": [ "myPartitionKey1" ] + }, + { + "kind": "Hash", + "name": "container-005", + "paths": [ + "myPartitionKey1" + ], + "version": 2 } ], "name": "all-partition-key-types" @@ -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` @@ -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. diff --git a/avm/res/document-db/database-account/gremlin-database/graph/main.json b/avm/res/document-db/database-account/gremlin-database/graph/main.json index 1779026f4f..2d4f0f12fa 100644 --- a/avm/res/document-db/database-account/gremlin-database/graph/main.json +++ b/avm/res/document-db/database-account/gremlin-database/graph/main.json @@ -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.", diff --git a/avm/res/document-db/database-account/gremlin-database/main.json b/avm/res/document-db/database-account/gremlin-database/main.json index c3cd9ee8c7..57548e1867 100644 --- a/avm/res/document-db/database-account/gremlin-database/main.json +++ b/avm/res/document-db/database-account/gremlin-database/main.json @@ -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.", @@ -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.", diff --git a/avm/res/document-db/database-account/main.bicep b/avm/res/document-db/database-account/main.bicep index 9e95fc47a2..3e8626e9c9 100644 --- a/avm/res/document-db/database-account/main.bicep +++ b/avm/res/document-db/database-account/main.bicep @@ -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? diff --git a/avm/res/document-db/database-account/main.json b/avm/res/document-db/database-account/main.json index f5121fe2cd..ec16d7c7a8 100644 --- a/avm/res/document-db/database-account/main.json +++ b/avm/res/document-db/database-account/main.json @@ -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.", @@ -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, @@ -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.", @@ -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')]" }, @@ -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.", @@ -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": { @@ -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": { diff --git a/avm/res/document-db/database-account/mongodb-database/collection/main.json b/avm/res/document-db/database-account/mongodb-database/collection/main.json index ae74132b53..eeb2943ec8 100644 --- a/avm/res/document-db/database-account/mongodb-database/collection/main.json +++ b/avm/res/document-db/database-account/mongodb-database/collection/main.json @@ -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.", diff --git a/avm/res/document-db/database-account/mongodb-database/main.json b/avm/res/document-db/database-account/mongodb-database/main.json index 781bd56a97..a862d99d20 100644 --- a/avm/res/document-db/database-account/mongodb-database/main.json +++ b/avm/res/document-db/database-account/mongodb-database/main.json @@ -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.", @@ -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.", diff --git a/avm/res/document-db/database-account/sql-database/container/README.md b/avm/res/document-db/database-account/sql-database/container/README.md index c8227d7ff2..122e23a6fd 100644 --- a/avm/res/document-db/database-account/sql-database/container/README.md +++ b/avm/res/document-db/database-account/sql-database/container/README.md @@ -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` @@ -126,7 +127,6 @@ Default to Hash. Indicates the kind of algorithm used for partitioning. [ 'Hash' 'MultiHash' - 'Range' ] ``` @@ -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 diff --git a/avm/res/document-db/database-account/sql-database/container/main.bicep b/avm/res/document-db/database-account/sql-database/container/main.bicep index 97f4a59e5b..902ee2ec8f 100644 --- a/avm/res/document-db/database-account/sql-database/container/main.bicep +++ b/avm/res/document-db/database-account/sql-database/container/main.bicep @@ -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}'] @@ -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) ? { diff --git a/avm/res/document-db/database-account/sql-database/container/main.json b/avm/res/document-db/database-account/sql-database/container/main.json index 815512145c..f882248bfc 100644 --- a/avm/res/document-db/database-account/sql-database/container/main.json +++ b/avm/res/document-db/database-account/sql-database/container/main.json @@ -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.", @@ -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": { @@ -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": { diff --git a/avm/res/document-db/database-account/sql-database/main.bicep b/avm/res/document-db/database-account/sql-database/main.bicep index a62ea3f09f..d79d8f1802 100644 --- a/avm/res/document-db/database-account/sql-database/main.bicep +++ b/avm/res/document-db/database-account/sql-database/main.bicep @@ -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 diff --git a/avm/res/document-db/database-account/sql-database/main.json b/avm/res/document-db/database-account/sql-database/main.json index 0419417fa5..3bce557b29 100644 --- a/avm/res/document-db/database-account/sql-database/main.json +++ b/avm/res/document-db/database-account/sql-database/main.json @@ -5,8 +5,8 @@ "metadata": { "_generator": { "name": "bicep", - "version": "0.26.54.24096", - "templateHash": "3826907101153138616" + "version": "0.27.1.19265", + "templateHash": "8319829662998768775" }, "name": "DocumentDB Database Account SQL Databases", "description": "This module deploys a SQL Database in a CosmosDB Account.", @@ -120,6 +120,9 @@ "kind": { "value": "[tryGet(parameters('containers')[copyIndex()], 'kind')]" }, + "version": { + "value": "[tryGet(parameters('containers')[copyIndex()], 'version')]" + }, "paths": { "value": "[tryGet(parameters('containers')[copyIndex()], 'paths')]" }, @@ -135,8 +138,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.", @@ -236,12 +239,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": { @@ -252,7 +265,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": { diff --git a/avm/res/document-db/database-account/tests/e2e/sqldb/main.test.bicep b/avm/res/document-db/database-account/tests/e2e/sqldb/main.test.bicep index 6662bd82a2..4d9362e8aa 100644 --- a/avm/res/document-db/database-account/tests/e2e/sqldb/main.test.bicep +++ b/avm/res/document-db/database-account/tests/e2e/sqldb/main.test.bicep @@ -278,6 +278,14 @@ module testDeployment '../../../main.bicep' = { 'myPartitionKey1' ] } + { + name: 'container-005' + kind: 'Hash' + version: 2 + paths: [ + 'myPartitionKey1' + ] + } ] name: 'all-partition-key-types' }