Skip to content

Commit

Permalink
[Feature Request] Add a possibility to specify partition key version …
Browse files Browse the repository at this point in the history
…for Hash partition key type (Azure#1921)

## Description

SQL database container defaults to 2 if omitted. This fixes that issue

Fixes Azure#1852 (closed by accident)


## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| 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

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 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

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->

---------

Co-authored-by: Bryan <[email protected]>
  • Loading branch information
2 people authored and hundredacres committed Jun 19, 2024
1 parent 798bc4d commit d9ffe27
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 33 deletions.
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

0 comments on commit d9ffe27

Please sign in to comment.