Skip to content

Commit 4ec1b87

Browse files
[documentdb] Add DocumentDB (Mongo vCore) CLI extension (#10059)
* [documentdb] Add DocumentDB (Mongo vCore) CLI extension Add the initial �z documentdb mongocluster extension for the Microsoft.DocumentDB/mongoClusters resource (API 2026-06-01), generated with aaz-dev plus custom refinements: - Flatten cluster create/update inputs into first-class flags (--admin-user/--admin-password, --tier, --storage-size/--storage-type, --shard-count, --high-availability, --data-api-mode, --auth-allowed-modes); the five provisioning inputs are required on create. - Use --cluster-name for the parent on all sub-resources. - Restrict managed identity to UserAssigned (service rejects SystemAssigned). - user create/update: custom --type/-t flag over the identityProvider discriminated union, and repeatable --role db=x role=y (singular_options). - Drop private-endpoint-connection / private-link-resource in favor of the generic az network commands. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Adding entry in service_name.json * [documentdb] Add reset-password, replica create, and restore wrappers Add three hand-written custom commands over the AAZ-generated mongocluster surface: - `mongocluster reset-password`: friendly wrapper over update that exposes only --password and maps it to the administrator object (other update flags hidden). - `mongocluster replica create`: creates a cross-region GeoReplica from a source cluster (--source-cluster / --source-location); sets createMode + replicaParameters internally. - `mongocluster restore`: point-in-time restore into a new cluster (--source-cluster / --restore-time + admin credentials); sets createMode + restoreParameters + administrator internally. Since AAZ drops hide=True args from generated code, the create-variant wrappers inject createMode/replicaParameters/restoreParameters via a content override (set_const + set_prop) rather than hidden args. Irrelevant create/update flags are deregistered so each command stays focused. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [documentdb] Enrich README and HISTORY Address PR feedback: expand the extension README with background, a command-group table, and usage examples for clusters, firewall rules, users, identity, replicas, reset-password, and point-in-time restore. Flesh out the 1.0.0b1 HISTORY entry with the customer-visible command surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [documentdb] Fix shared arg-schema cache across wrapper commands The reset-password, replica-create, and restore wrappers subclass the generated Create/Update commands. AAZ caches the built arguments schema in the class attribute ``_arguments_schema`` (used by get_arguments_schema, the CLI parser entry point). Because the wrappers inherit that attribute from their base command, when the base command (create/update) loaded its schema first in the same process, the wrapper reused the base's cached schema and never applied its own option rename/deregistration -- e.g. ``reset-password`` failed with "unrecognized arguments: --password". Give each wrapper its own ``_arguments_schema = None`` (and ``_args_schema = None`` for the internal build cache) so every wrapper builds and caches an isolated schema. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [documentdb] Add end-to-end mongocluster scenario test Add a recorded ScenarioTest covering the full mongo cluster lifecycle: check-name-availability, create, show, list, update (tags), reset-password, firewall-rule create/show/list/delete, and delete. Every long-running operation uses --no-wait immediately followed by the matching wait command so each step observes a settled state and the scenario is free of state-condition races. Includes the recorded cassette for offline playback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [documentdb] Make core provisioning args required on create Mark admin-user, admin-password, tier, storage-size, shard-count, and high-availability as required on `mongocluster create`, matching the AAZ command model. This gives a clear client-side error when a core provisioning input is omitted instead of a server-side 400. storage-type stays optional, and update keeps all of these optional so a single property can be changed in isolation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8c1dc9d commit 4ec1b87

55 files changed

Lines changed: 15240 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/documentdb/HISTORY.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. :changelog:
2+
3+
Release History
4+
===============
5+
6+
1.0.0b1
7+
+++++++
8+
* Initial release of the DocumentDB (Azure Cosmos DB for MongoDB vCore) extension.
9+
* Add ``az documentdb mongocluster`` commands to create, update, show, list, and delete
10+
mongo clusters, list connection strings, and check name availability.
11+
* Add ``az documentdb mongocluster firewall-rule`` commands to manage IP firewall rules.
12+
* Add ``az documentdb mongocluster user`` commands to manage Microsoft Entra-backed
13+
database users.
14+
* Add ``az documentdb mongocluster identity`` commands to manage the cluster's
15+
user-assigned managed identity.
16+
* Add ``az documentdb mongocluster replica`` commands to list and promote read replicas,
17+
and ``replica create`` to create a cross-region GeoReplica.
18+
* Add ``az documentdb mongocluster restore`` for point-in-time restore into a new cluster.
19+
* Add ``az documentdb mongocluster reset-password`` to reset the administrator password.

src/documentdb/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Azure CLI DocumentDB Extension #
2+
3+
This is an extension to Azure CLI to manage **Azure Cosmos DB for MongoDB (vCore)**
4+
clusters — the `Microsoft.DocumentDB/mongoClusters` resource — under the
5+
`az documentdb mongocluster` command group.
6+
7+
## How to install ##
8+
9+
```bash
10+
az extension add --name documentdb
11+
```
12+
13+
## Background ##
14+
15+
DocumentDB (Mongo vCore) is a fully managed, MongoDB-compatible database service.
16+
This extension exposes the management-plane operations for mongo clusters and their
17+
sub-resources: IP firewall rules, Microsoft Entra-backed database users, user-assigned
18+
managed identity, cross-region read replicas, and point-in-time restore.
19+
20+
## Command groups ##
21+
22+
| Group | Description |
23+
|--|--|
24+
| `az documentdb mongocluster` | Create and manage mongo clusters |
25+
| `az documentdb mongocluster firewall-rule` | Manage IP firewall rules (public access) |
26+
| `az documentdb mongocluster user` | Manage Microsoft Entra-backed database users |
27+
| `az documentdb mongocluster identity` | Manage the cluster's user-assigned managed identity |
28+
| `az documentdb mongocluster replica` | List, create, and promote cross-region read replicas |
29+
30+
## Usage examples ##
31+
32+
### Create and manage a cluster
33+
34+
```bash
35+
# Create a cluster
36+
az documentdb mongocluster create -n MyCluster -g MyResourceGroup --location eastus2 \
37+
--admin-user dbadmin --admin-password MyP@ssw0rd123! \
38+
--tier M30 --storage-size 128 --storage-type PremiumSSDv2 \
39+
--shard-count 1 --high-availability Disabled
40+
41+
# Show and list
42+
az documentdb mongocluster show -n MyCluster -g MyResourceGroup
43+
az documentdb mongocluster list -g MyResourceGroup
44+
45+
# Get connection strings
46+
az documentdb mongocluster list-connection-strings -n MyCluster -g MyResourceGroup
47+
48+
# Reset the administrator password
49+
az documentdb mongocluster reset-password -n MyCluster -g MyResourceGroup --password NewP@ssw0rd123!
50+
51+
# Delete
52+
az documentdb mongocluster delete -n MyCluster -g MyResourceGroup
53+
```
54+
55+
### Firewall rules
56+
57+
```bash
58+
az documentdb mongocluster firewall-rule create -n AllowMyIp --cluster-name MyCluster \
59+
-g MyResourceGroup --start-ip-address 203.0.113.0 --end-ip-address 203.0.113.255
60+
az documentdb mongocluster firewall-rule list --cluster-name MyCluster -g MyResourceGroup
61+
```
62+
63+
### Microsoft Entra-backed users
64+
65+
```bash
66+
az documentdb mongocluster user create -n alice --cluster-name MyCluster -g MyResourceGroup \
67+
--type User --role db=admin role=root
68+
```
69+
70+
### Managed identity (user-assigned)
71+
72+
```bash
73+
az documentdb mongocluster identity assign -n MyCluster -g MyResourceGroup \
74+
--mi-user-assigned <userAssignedIdentityResourceId>
75+
az documentdb mongocluster identity show -n MyCluster -g MyResourceGroup
76+
```
77+
78+
### Replicas (cross-region)
79+
80+
```bash
81+
# List the parent cluster's replicas
82+
az documentdb mongocluster replica list --cluster-name MyCluster -g MyResourceGroup
83+
84+
# Create a cross-region GeoReplica (the source must have the GeoReplicas preview feature enabled)
85+
az documentdb mongocluster replica create -n MyReplica -g MyResourceGroup -l centralus \
86+
--source-cluster MyCluster --source-location eastus2
87+
88+
# Promote a replica to primary
89+
az documentdb mongocluster replica promote -n MyReplica -g MyResourceGroup
90+
```
91+
92+
### Point-in-time restore
93+
94+
```bash
95+
az documentdb mongocluster restore -n RestoredCluster -g MyResourceGroup --location eastus2 \
96+
--source-cluster MyCluster --restore-time "2026-06-30T10:00:00Z" \
97+
--admin-user dbadmin --admin-password MyP@ssw0rd123!
98+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
from azure.cli.core import AzCommandsLoader
9+
from azext_documentdb._help import helps # pylint: disable=unused-import
10+
11+
12+
class DocumentdbCommandsLoader(AzCommandsLoader):
13+
14+
def __init__(self, cli_ctx=None):
15+
from azure.cli.core.commands import CliCommandType
16+
custom_command_type = CliCommandType(
17+
operations_tmpl='azext_documentdb.custom#{}')
18+
super().__init__(cli_ctx=cli_ctx,
19+
custom_command_type=custom_command_type)
20+
21+
def load_command_table(self, args):
22+
from azext_documentdb.commands import load_command_table
23+
from azure.cli.core.aaz import load_aaz_command_table
24+
try:
25+
from . import aaz
26+
except ImportError:
27+
aaz = None
28+
if aaz:
29+
load_aaz_command_table(
30+
loader=self,
31+
aaz_pkg_name=aaz.__name__,
32+
args=args
33+
)
34+
load_command_table(self, args)
35+
return self.command_table
36+
37+
def load_arguments(self, command):
38+
from azext_documentdb._params import load_arguments
39+
load_arguments(self, command)
40+
41+
42+
COMMAND_LOADER_CLS = DocumentdbCommandsLoader
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: disable=line-too-long
9+
# pylint: disable=too-many-lines
10+
11+
from knack.help_files import helps # pylint: disable=unused-import
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: disable=too-many-lines
9+
# pylint: disable=too-many-statements
10+
11+
12+
def load_arguments(self, _): # pylint: disable=unused-argument
13+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"documentdb",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Document Db
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"documentdb mongocluster",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Mongo Cluster
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]

0 commit comments

Comments
 (0)