Skip to content

Commit a5d989b

Browse files
feat: Update avm/res/document-db/mongo-cluster module to support Microsoft Entra user entities (#5260)
## Description I'm adding a new `user` submodule to `avm/res/document-db/mongo-cluster` so we can build Azure Developer CLI templates that support Microsoft Entra authentication end-to-end. Here's the relevant documentation: <https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/how-to-configure-entra-authentication> Unfortunately, this module was using an older RP, so this caused a few "domino" changes: - The `api-version` needed to be updated to at least `2025-04-01-preview` to support Microsoft Entra authentication - The `nodeType` property no longer exists in the last API version - The `highAvailabilityMode` property is now a string with multiple allowed values And in keeping with best practices, I just made these minor changes: - I updated most unit tests to deploy minimal single-node resources to minimize the amount of churn and extra resources deployed for each CI run - I updated the WAF-aligned unit test to deploy triplicate nodes that are zone-redundant (no redundancy in the initial version) - I updated the metadata to correctly reference *"Azure Cosmos DB for MongoDB (vCore)"* - The WAF-aligned unit test needed tags to suppress a warning from PSRule I did notice this behavior, but I didn't fix it in this PR: - The `max.*` unit test has transient failures. I couldn't pin down what was causing it, but it was due to the test not being able to "find" the nested dependencies. I don't have enough information to diagnose if it was a race condition or a naming collision. Finally, I didn't suppress the Bicep linter warning for the `api-version`. That API version is supported in the REST API, but it's not documented in the specs yet. This PR depends on this other change to remove linter warnings: - Azure/azure-rest-api-specs#34580 > [!NOTE] > I tried my best to scope my changes to the minimal necessary to add this submodule and Entra authentication support. ## Pipeline Reference | Pipeline | | --- | | [![avm.res.document-db.mongo-cluster](https://github.com/seesharprun/bicep-registry-modules/actions/workflows/avm.res.document-db.mongo-cluster.yml/badge.svg)](https://github.com/seesharprun/bicep-registry-modules/actions/workflows/avm.res.document-db.mongo-cluster.yml) | ## Type of Change - [ ] Update to CI Environment or utilities (Non-module affecting changes) - [x] Azure Verified Module updates: - [ ] 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. - [x] Feature update backwards compatible feature updates, and I have bumped the MINOR version in `version.json`. - [x] Breaking changes and I have bumped the MAJOR version in `version.json`. - [x] 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: Alexander Sehr <[email protected]>
1 parent ee25000 commit a5d989b

File tree

16 files changed

+1117
-153
lines changed

16 files changed

+1117
-153
lines changed

avm/res/document-db/mongo-cluster/README.md

Lines changed: 261 additions & 53 deletions
Large diffs are not rendered by default.

avm/res/document-db/mongo-cluster/firewall-rule/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Azure Cosmos DB MongoDB vCore Cluster Config FireWall Rules `[Microsoft.DocumentDB/mongoClusters/firewallRules]`
1+
# Azure Cosmos DB for MongoDB (vCore) cluster Config FireWall Rules `[Microsoft.DocumentDB/mongoClusters/firewallRules]`
22

3-
This module config firewall rules for the Azure Cosmos DB MongoDB vCore cluster.
3+
This module config firewall rules for the Azure Cosmos DB for MongoDB (vCore) cluster.
44

55
## Navigation
66

@@ -12,27 +12,27 @@ This module config firewall rules for the Azure Cosmos DB MongoDB vCore cluster.
1212

1313
| Resource Type | API Version |
1414
| :-- | :-- |
15-
| `Microsoft.DocumentDB/mongoClusters/firewallRules` | [2024-02-15-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DocumentDB/2024-02-15-preview/mongoClusters/firewallRules) |
15+
| `Microsoft.DocumentDB/mongoClusters/firewallRules` | [2024-10-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DocumentDB/2024-10-01-preview/mongoClusters/firewallRules) |
1616

1717
## Parameters
1818

1919
**Required parameters**
2020

2121
| Parameter | Type | Description |
2222
| :-- | :-- | :-- |
23-
| [`endIpAddress`](#parameter-endipaddress) | string | The end IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format. |
23+
| [`endIpAddress`](#parameter-endipaddress) | string | The end IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format. |
2424
| [`name`](#parameter-name) | string | The name of the firewall rule. Must match the pattern `^[a-zA-Z0-9][-_a-zA-Z0-9]*`. |
25-
| [`startIpAddress`](#parameter-startipaddress) | string | The start IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format. |
25+
| [`startIpAddress`](#parameter-startipaddress) | string | The start IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format. |
2626

2727
**Conditional parameters**
2828

2929
| Parameter | Type | Description |
3030
| :-- | :-- | :-- |
31-
| [`mongoClusterName`](#parameter-mongoclustername) | string | The name of the parent Azure Cosmos DB MongoDB vCore cluster. Required if the template is used in a standalone deployment. |
31+
| [`mongoClusterName`](#parameter-mongoclustername) | string | The name of the parent Azure Cosmos DB for MongoDB (vCore) cluster. Required if the template is used in a standalone deployment. |
3232

3333
### Parameter: `endIpAddress`
3434

35-
The end IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format.
35+
The end IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format.
3636

3737
- Required: Yes
3838
- Type: string
@@ -46,14 +46,14 @@ The name of the firewall rule. Must match the pattern `^[a-zA-Z0-9][-_a-zA-Z0-9]
4646

4747
### Parameter: `startIpAddress`
4848

49-
The start IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format.
49+
The start IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format.
5050

5151
- Required: Yes
5252
- Type: string
5353

5454
### Parameter: `mongoClusterName`
5555

56-
The name of the parent Azure Cosmos DB MongoDB vCore cluster. Required if the template is used in a standalone deployment.
56+
The name of the parent Azure Cosmos DB for MongoDB (vCore) cluster. Required if the template is used in a standalone deployment.
5757

5858
- Required: Yes
5959
- Type: string
@@ -63,5 +63,5 @@ The name of the parent Azure Cosmos DB MongoDB vCore cluster. Required if the te
6363
| Output | Type | Description |
6464
| :-- | :-- | :-- |
6565
| `name` | string | The name of the firewall rule. |
66-
| `resourceGroupName` | string | The name of the resource group the Azure Cosmos DB MongoDB vCore cluster was created in. |
66+
| `resourceGroupName` | string | The name of the resource group the Azure Cosmos DB for MongoDB (vCore) cluster was created in. |
6767
| `resourceId` | string | The resource ID of the firewall rule. |

avm/res/document-db/mongo-cluster/firewall-rule/main.bicep

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
metadata name = 'Azure Cosmos DB MongoDB vCore Cluster Config FireWall Rules'
2-
metadata description = 'This module config firewall rules for the Azure Cosmos DB MongoDB vCore cluster.'
1+
metadata name = 'Azure Cosmos DB for MongoDB (vCore) cluster Config FireWall Rules'
2+
metadata description = 'This module config firewall rules for the Azure Cosmos DB for MongoDB (vCore) cluster.'
33

4-
@description('Conditional. The name of the parent Azure Cosmos DB MongoDB vCore cluster. Required if the template is used in a standalone deployment.')
4+
@description('Conditional. The name of the parent Azure Cosmos DB for MongoDB (vCore) cluster. Required if the template is used in a standalone deployment.')
55
param mongoClusterName string
66

77
@description('Required. The name of the firewall rule. Must match the pattern `^[a-zA-Z0-9][-_a-zA-Z0-9]*`.')
88
param name string
99

10-
@description('Required. The start IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format.')
10+
@description('Required. The start IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format.')
1111
param startIpAddress string
1212

13-
@description('Required. The end IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format.')
13+
@description('Required. The end IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format.')
1414
param endIpAddress string
1515

16-
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2024-02-15-preview' existing = {
16+
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2024-10-01-preview' existing = {
1717
name: mongoClusterName
1818
}
1919

20-
resource firewallRule 'Microsoft.DocumentDB/mongoClusters/firewallRules@2024-02-15-preview' = {
20+
resource firewallRule 'Microsoft.DocumentDB/mongoClusters/firewallRules@2024-10-01-preview' = {
2121
name: !contains(name, '.') // Custom validation as documented regex is incorrect and does fail with an 'InternalServerError'
2222
? name
2323
: fail('The firewall rule name must match the pattern `^[a-zA-Z0-9][-_a-zA-Z0-9]*`. A `.` is **not** allowed.')
@@ -28,7 +28,7 @@ resource firewallRule 'Microsoft.DocumentDB/mongoClusters/firewallRules@2024-02-
2828
}
2929
}
3030

31-
@description('The name of the resource group the Azure Cosmos DB MongoDB vCore cluster was created in.')
31+
@description('The name of the resource group the Azure Cosmos DB for MongoDB (vCore) cluster was created in.')
3232
output resourceGroupName string = resourceGroup().name
3333

3434
@description('The name of the firewall rule.')

avm/res/document-db/mongo-cluster/firewall-rule/main.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
"metadata": {
55
"_generator": {
66
"name": "bicep",
7-
"version": "0.34.44.8038",
8-
"templateHash": "4427483613542642631"
7+
"version": "0.35.1.17967",
8+
"templateHash": "16764717011313154043"
99
},
10-
"name": "Azure Cosmos DB MongoDB vCore Cluster Config FireWall Rules",
11-
"description": "This module config firewall rules for the Azure Cosmos DB MongoDB vCore cluster."
10+
"name": "Azure Cosmos DB for MongoDB (vCore) cluster Config FireWall Rules",
11+
"description": "This module config firewall rules for the Azure Cosmos DB for MongoDB (vCore) cluster."
1212
},
1313
"parameters": {
1414
"mongoClusterName": {
1515
"type": "string",
1616
"metadata": {
17-
"description": "Conditional. The name of the parent Azure Cosmos DB MongoDB vCore cluster. Required if the template is used in a standalone deployment."
17+
"description": "Conditional. The name of the parent Azure Cosmos DB for MongoDB (vCore) cluster. Required if the template is used in a standalone deployment."
1818
}
1919
},
2020
"name": {
@@ -26,20 +26,20 @@
2626
"startIpAddress": {
2727
"type": "string",
2828
"metadata": {
29-
"description": "Required. The start IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format."
29+
"description": "Required. The start IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format."
3030
}
3131
},
3232
"endIpAddress": {
3333
"type": "string",
3434
"metadata": {
35-
"description": "Required. The end IP address of the Azure Cosmos DB MongoDB vCore cluster firewall rule. Must be IPv4 format."
35+
"description": "Required. The end IP address of the Azure Cosmos DB for MongoDB (vCore) cluster firewall rule. Must be IPv4 format."
3636
}
3737
}
3838
},
3939
"resources": [
4040
{
4141
"type": "Microsoft.DocumentDB/mongoClusters/firewallRules",
42-
"apiVersion": "2024-02-15-preview",
42+
"apiVersion": "2024-10-01-preview",
4343
"name": "[format('{0}/{1}', parameters('mongoClusterName'), if(not(contains(parameters('name'), '.')), parameters('name'), fail('The firewall rule name must match the pattern `^[a-zA-Z0-9][-_a-zA-Z0-9]*`. A `.` is **not** allowed.')))]",
4444
"properties": {
4545
"startIpAddress": "[parameters('startIpAddress')]",
@@ -51,7 +51,7 @@
5151
"resourceGroupName": {
5252
"type": "string",
5353
"metadata": {
54-
"description": "The name of the resource group the Azure Cosmos DB MongoDB vCore cluster was created in."
54+
"description": "The name of the resource group the Azure Cosmos DB for MongoDB (vCore) cluster was created in."
5555
},
5656
"value": "[resourceGroup().name]"
5757
},

avm/res/document-db/mongo-cluster/main.bicep

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
metadata name = 'Azure Cosmos DB MongoDB vCore cluster'
2-
metadata description = '''This module deploys a Azure Cosmos DB MongoDB vCore cluster.
1+
metadata name = 'Azure Cosmos DB for MongoDB (vCore) cluster'
2+
metadata description = '''This module deploys a Azure Cosmos DB for MongoDB (vCore) cluster.
33
44
**Note:** This module is not intended for broad, generic use, as it was designed to cater for the requirements of the AZD CLI product. Feature requests and bug fix requests are welcome if they support the development of the AZD CLI but may not be incorporated if they aim to make this module more generic than what it needs to be for its primary use case.'''
55

6-
@description('Required. Name of the Azure Cosmos DB MongoDB vCore cluster.')
6+
@description('Required. Name of the Azure Cosmos DB for MongoDB (vCore) cluster.')
77
param name string
88

99
@description('Optional. Default to current resource group scope location. Location for all resources.')
@@ -21,7 +21,7 @@ param administratorLogin string
2121
@maxLength(128)
2222
param administratorLoginPassword string
2323

24-
@description('Optional. Mode to create the azure cosmos db mongodb vCore cluster.')
24+
@description('Optional. Mode to create the Azure Cosmos DB for MongoDB (vCore) cluster.')
2525
param createMode string = 'Default'
2626

2727
import { diagnosticSettingFullType } from 'br/public:avm/utl/types/avm-common-types:0.5.1'
@@ -32,7 +32,12 @@ param diagnosticSettings diagnosticSettingFullType[]?
3232
param enableTelemetry bool = true
3333

3434
@description('Optional. Whether high availability is enabled on the node group.')
35-
param highAvailabilityMode bool = false
35+
@allowed([
36+
'Disabled'
37+
'SameZone'
38+
'ZoneRedundantPreferred'
39+
])
40+
param highAvailabilityMode string = 'ZoneRedundantPreferred'
3641

3742
import { lockType } from 'br/public:avm/utl/types/avm-common-types:0.5.1'
3843
@description('Optional. The lock settings of the service.')
@@ -44,9 +49,6 @@ param networkAcls networkAclsType?
4449
@description('Required. Number of nodes in the node group.')
4550
param nodeCount int
4651

47-
@description('Optional. Deployed Node type in the node group.')
48-
param nodeType string = 'Shard'
49-
5052
import { privateEndpointSingleServiceType } from 'br/public:avm/utl/types/avm-common-types:0.5.1'
5153
@description('Optional. Configuration details for private endpoints. For security reasons, it is recommended to use private endpoints whenever possible.')
5254
param privateEndpoints privateEndpointSingleServiceType[]?
@@ -64,6 +66,12 @@ param sku string
6466
@description('Required. Disk storage size for the node group in GB.')
6567
param storage int
6668

69+
@description('Optional. The type of the secrets export configuration.')
70+
param enableMicrosoftEntraAuth bool = false
71+
72+
@description('Optional. The Microsoft Entra ID authentication identity assignments to be created for the cluster.')
73+
param entraAuthIdentities authIdentityType[]?
74+
6775
var enableReferencedModulesTelemetry = false
6876

6977
var builtInRoleNames = {
@@ -136,23 +144,40 @@ resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableT
136144
}
137145
}
138146

139-
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2024-02-15-preview' = {
147+
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2025-04-01-preview' = {
140148
name: name
141149
tags: tags
142150
location: location
143151
properties: {
144-
administratorLogin: administratorLogin
145-
administratorLoginPassword: administratorLoginPassword
152+
administrator: {
153+
userName: administratorLogin
154+
password: administratorLoginPassword
155+
}
146156
createMode: createMode
147-
nodeGroupSpecs: [
148-
{
149-
diskSizeGB: storage
150-
enableHa: highAvailabilityMode
151-
kind: nodeType
152-
nodeCount: nodeCount
153-
sku: sku
154-
}
155-
]
157+
compute: {
158+
tier: sku
159+
}
160+
sharding: {
161+
shardCount: nodeCount
162+
}
163+
storage: {
164+
sizeGb: storage
165+
}
166+
highAvailability: {
167+
targetMode: highAvailabilityMode
168+
}
169+
authConfig: {
170+
allowedModes: union(
171+
[
172+
'NativeAuth'
173+
],
174+
enableMicrosoftEntraAuth
175+
? [
176+
'MicrosoftEntraID'
177+
]
178+
: []
179+
)
180+
}
156181
}
157182
}
158183

@@ -213,6 +238,20 @@ module mongoCluster_configFireWallRules 'firewall-rule/main.bicep' = [
213238
}
214239
]
215240

241+
module mongoCluster_users 'user/main.bicep' = [
242+
for (targetIdentity, index) in (entraAuthIdentities ?? []): {
243+
name: '${uniqueString(deployment().name, location)}-user-${index}'
244+
params: {
245+
mongoClusterName: mongoCluster.name
246+
location: location
247+
targetIdentity: {
248+
principalId: targetIdentity.principalId
249+
principalType: targetIdentity.principalType ?? 'ServicePrincipal'
250+
}
251+
}
252+
}
253+
]
254+
216255
module secretsExport 'modules/keyVaultExport.bicep' = if (secretsExportConfiguration != null) {
217256
name: '${uniqueString(deployment().name, location)}-secrets-kv'
218257
scope: resourceGroup(
@@ -290,10 +329,10 @@ module mongoCluster_privateEndpoints 'br/public:avm/res/network/private-endpoint
290329
}
291330
]
292331

293-
@description('The name of the Azure Cosmos DB MongoDB vCore cluster.')
332+
@description('The name of the Azure Cosmos DB for MongoDB (vCore) cluster.')
294333
output name string = mongoCluster.name
295334

296-
@description('The resource ID of the Azure Cosmos DB MongoDB vCore cluster.')
335+
@description('The resource ID of the Azure Cosmos DB for MongoDB (vCore) cluster.')
297336
output mongoClusterResourceId string = mongoCluster.id
298337

299338
@description('The resource ID of the resource group the firewall rule was created in.')
@@ -408,3 +447,13 @@ type secretsOutputType = {
408447
@description('An exported secret\'s references.')
409448
*: secretSetType
410449
}
450+
451+
@export()
452+
@description('The type for identities that can be used for Microsoft Entra ID authentication.')
453+
type authIdentityType = {
454+
@description('Required. The principal (object) ID of the identity to create as a user on the cluster.')
455+
principalId: string
456+
457+
@description('Optional. The type of principal to be used for the identity provider. Defaults to "ServicePrincipal".')
458+
principalType: 'ServicePrincipal' | 'User'?
459+
}

0 commit comments

Comments
 (0)