SDK Azure.ResourceManager.MongoDBAtlas
Gérez les organisations MongoDB Atlas en tant que ressources Azure ARM avec une facturation unifiée via Azure Marketplace.
Informations sur le package
| Propriété |
Valeur |
| Pack |
Azure.ResourceManager.MongoDBAtlas |
| Version |
1.0.0 (GA) |
| Version de l'API |
01/06/2025 |
| Type de ressource |
MongoDB.Atlas/organizations |
| NuGet |
Azure.ResourceManager.MongoDBAtlas |
Installation
dotnet add package Azure.ResourceManager.MongoDBAtlas
dotnet add package Azure.Identity
dotnet add package Azure.ResourceManager
Limitation importante de la portée
Ce SDK gère les organisations MongoDB Atlas en tant que ressources Azure ARM pour l'intégration au Marketplace. Il ne gère PAS directement :
- les clusters Atlas
- les bases de données
- les collections
- Les utilisateurs/rôles
Pour la gestion des clusters, utilisez directement l'API MongoDB Atlas après avoir créé l'organisation.
Variables d’environnement
AZURE_SUBSCRIPTION_ID= # Obligatoire : ID d’abonnement Azure
AZURE_RESOURCE_GROUP= # Obligatoire : nom du groupe de ressources Azure
AZURE_TOKEN_CREDENTIALS=prod # Obligatoire uniquement si DefaultAzureCredential est utilisé en production
AZURE_TENANT_ID= # Pour l’authentification par entité de service (facultatif)
AZURE_CLIENT_ID= # Pour l’authentification par entité de service (facultatif)
AZURE_CLIENT_SECRET= # Pour l’authentification par entité de service (facultatif)
Authentification
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MongoDBAtlas;
using Azure.ResourceManager.MongoDBAtlas.Models;
// Développement local : DefaultAzureCredential. En production : définissez AZURE_TOKEN_CREDENTIALS=prod ou AZURE_TOKEN_CREDENTIALS=
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Ou utilisez directement des informations d’identification spécifiques en production :
// Voir https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
Types de base
| Type |
Objectif |
MongoDBAtlasOrganizationResource |
Ressource ARM représentant une organisation Atlas |
MongoDBAtlasOrganizationCollection |
Collection d'organisations au sein d'un groupe de ressources |
MongoDBAtlasOrganizationData |
Modèle de données pour la ressource « organisation » |
MongoDBAtlasOrganizationProperties |
Propriétés spécifiques à l'organisation |
MongoDBAtlasMarketplaceDetails |
Détails de l'abonnement Azure Marketplace |
MongoDBAtlasOfferDetails |
Configuration de l'offre sur le Marketplace |
MongoDBAtlasUserDetails |
Informations sur les utilisateurs de l'organisation |
MongoDBAtlasPartnerProperties |
Propriétés spécifiques à MongoDB (nom de l'organisation, ID) |
Workflows
Récupérer la collection « Organisation »
// Récupérer le groupe de ressources
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroup = await subscription.GetResourceGroupAsync("my-resource-group");
// Récupérer la collection des organisations
MongoDBAtlasOrganizationCollection organizations =
resourceGroup.Value.GetMongoDBAtlasOrganizations();
Créer une organisation
var organizationName = "my-atlas-org";
var location = AzureLocation.EastUS2;
// Créer les données de l’organisation
var organizationData = new MongoDBAtlasOrganizationData(location)
{
Properties = new MongoDBAtlasOrganizationProperties(
marketplace: new MongoDBAtlasMarketplaceDetails(
subscriptionId: "your-azure-subscription-id",
offerDetails : new MongoDBAtlasOfferDetails(
publisherId : "mongodb",
offerId : "mongodb_atlas_azure_native_prod",
planId : "private_plan",
planName : « Pay as You Go (Gratuit) (Privé) »,
durée : « P1M »,
identifiant de la durée : « gmz7xq9ge3py »
)
),
user : new MongoDBAtlasUserDetails(
emailAddress : "[email protected]",
upn : "[email protected]"
)
{
FirstName = "Admin",
LastName = "User"
}
)
{
PartnerProperties = new MongoDBAtlasPartnerProperties
{
OrganizationName = organizationName
}
},
Tags = { ["Environment"] = "Production" }
};
// Créer l'organisation (opération de longue durée)
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Completed,
organizationName,
organizationData
);
MongoDBAtlasOrganizationResource organization = operation.Value;
Console.WriteLine($"Créée : {organization.Id}");
Récupérer une organisation existante
// Option 1 : à partir d'une collection
MongoDBAtlasOrganizationResource org =
await organizations.GetAsync("my-atlas-org");
// Option 2 : à partir d'un identifiant de ressource
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
subscriptionId: "subscription-id",
resourceGroupName: "my-resource-group",
organizationName: "my-atlas-org"
);
MongoDBAtlasOrganizationResource org2 =
armClient.GetMongoDBAtlasOrganizationResource(resourceId);
await org2.GetAsync(); // Récupérer les données
Liste des organisations
// Liste des organisations dans le groupe de ressources
await foreach (var org in organizations.GetAllAsync())
{
Console.WriteLine($"Organisation : {org.Data.Name}");
Console.WriteLine($" Emplacement : {org.Data.Location}");
Console.WriteLine($" État : {org.Data.Properties?.ProvisioningState}");
}
// Liste dans l'ensemble de l'abonnement
await foreach (var org in subscription.GetMongoDBAtlasOrganizationsAsync())
{
Console.WriteLine($"Organisation : {org.Data.Name} dans {org.Data.Id}");
}
Mise à jour des balises
// Ajouter un seul tag
await organization.AddTagAsync("CostCenter", "12345");
// Remplacer tous les tags
await organization.SetTagsAsync(new Dictionary
{
["Environment"] = "Production",
["Team"] = "Platform"
});
// Supprimer un tag
await organization.RemoveTagAsync("OldTag");
Mettre à jour les propriétés de l’organisation
var patch = new MongoDBAtlasOrganizationPatch
{
Tags = { ["UpdatedAt"] = DateTime.UtcNow.ToString("o") },
Properties = new MongoDBAtlasOrganizationUpdateProperties
{
// Mettre à jour les informations utilisateur si nécessaire
User = new MongoDBAtlasUserDetails(
emailAddress: "[email protected]",
upn: "[email protected]"
)
}
};
var updateOperation = await organization.UpdateAsync(
WaitUntil.Completed,
patch
);
Supprimer une organisation
// Supprimer (opération de longue durée)
await organization.DeleteAsync(WaitUntil.Completed);
Référence des propriétés du modèle
MongoDBAtlasOrganizationProperties
| Propriété |
Type |
Description |
Marketplace |
MongoDBAtlasMarketplaceDetails |
Obligatoire. Détails de l'abonnement à la place de marché |
Utilisateur |
MongoDBAtlasUserDetails |
Obligatoire. Utilisateur administrateur de l'organisation |
Propriétés du partenaire |
MongoDBAtlasPartnerProperties |
Propriétés spécifiques à MongoDB |
ProvisioningState |
MongoDBAtlasResourceProvisioningState |
En lecture seule. État actuel de l'approvisionnement |
MongoDBAtlasMarketplaceDetails
| Propriété |
Type |
Description |
SubscriptionId |
chaîne de caractères |
Obligatoire. ID d'abonnement Azure pour la facturation |
Détails de l'offre |
MongoDBAtlasOfferDetails |
Obligatoire. Configuration de l'offre sur la Marketplace |
État de l'abonnement |
MarketplaceSubscriptionStatus |
En lecture seule. Statut de l'abonnement |
MongoDBAtlasOfferDetails
| Propriété |
Type |
Description |
PublisherId |
chaîne de caractères |
Obligatoire. Identifiant de l'éditeur (généralement « mongodb ») |
OfferId |
chaîne |
Obligatoire. ID de l'offre |
PlanId |
chaîne |
Obligatoire. ID du forfait |
PlanName |
chaîne |
Obligatoire. Nom d'affichage du plan |
Unité de durée |
chaîne |
Obligatoire. Unité de facturation (par exemple, « P1M ») |
TermId |
chaîne |
Obligatoire. Identifiant de la période |
MongoDBAtlasUserDetails
| Propriété |
Type |
Description |
Adresse e-mail |
chaîne de caractères |
Obligatoire. Adresse e-mail de l'utilisateur |
UPN |
chaîne |
Obligatoire. Nom principal de l'utilisateur |
Prénom |
chaîne |
Facultatif. Prénom de l'utilisateur |
Nom |
chaîne |
Facultatif. Nom de famille de l'utilisateur |
MongoDBAtlasPartnerProperties
| Propriété |
Type |
Description |
OrganizationName |
chaîne |
Nom de l'organisation MongoDB Atlas |
Identifiant de l'organisation |
chaîne |
En lecture seule. ID de l'organisation MongoDB Atlas |
États de provisionnement
| État |
Description |
Réussi |
Ressource provisionnée avec succès |
Échec |
Échec de l'allocation |
Annulé |
Le provisionnement a été annulé |
Provisionnement en cours |
La ressource est en cours de provisionnement |
Mise à jour |
La ressource est en cours de mise à jour |
Suppression |
La ressource est en cours de suppression |
Acceptée |
Demande acceptée, provisionnement en cours |
Statut de l'abonnement à la Marketplace
| Statut |
Description |
En attente du début de l’exécution |
Abonnement en attente d'activation |
Abonné |
Abonnement actif |
Suspendu |
Abonnement suspendu |
Désabonné |
Abonnement résilié |
Bonnes pratiques
Utiliser les méthodes asynchrones
// Privilégiez les méthodes asynchrones pour toutes les opérations
var org = await organizations.GetAsync("my-org");
await org.Value.AddTagAsync("key", "value");
Gérer les opérations de longue durée
// Attendre la fin de l'opération
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Completed, // Bloque jusqu'à la fin de l'opération
name,
data
);
// Ou lancer l'opération et vérifier son état ultérieurement
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Started, // Renvoie immédiatement
name,
data
);
// Vérifier si l'opération est terminée
while (!operation.HasCompleted)
{
await Task.Delay(TimeSpan.FromSeconds(5));
await operation.UpdateStatusAsync();
}
Vérifier l’état de provisionnement
var org = await organizations.GetAsync("my-org");
if (org.Value.Data.Properties?.ProvisioningState ==
MongoDBAtlasResourceProvisioningState.Succeeded)
{
Console.WriteLine("L'organisation est prête");
}
Utiliser les identifiants de ressource
// Créer un identifiant sans appel d’API
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
subscriptionId,
resourceGroupName,
organizationName
);
// Récupérer le descripteur de ressource (aucune donnée pour l'instant)
var orgResource = armClient.GetMongoDBAtlasOrganizationResource(resourceId);
// Récupérer les données lorsque cela est nécessaire
var response = await orgResource.GetAsync();
Erreurs courantes
| Erreur |
Cause |
Solution |
ResourceNotFound |
L'organisation n'existe pas |
Vérifiez le nom et le groupe de ressources |
Échec de l'autorisation |
Autorisations insuffisantes |
Vérifiez les rôles RBAC du groupe de ressources |
Paramètre non valide |
Propriétés obligatoires manquantes |
Assurez-vous que tous les champs obligatoires sont renseignés |
MarketplaceError |
Problème d'abonnement sur la Marketplace |
Vérifiez les détails de l'offre et de l'abonnement |
Ressources associées
- Microsoft Learn : MongoDB Atlas sur Azure
- Référence API
- SDK Azure pour .NET
Voir sur GitHub
---
name: azure-mgmt-mongodbatlas-dotnet
description: Manage MongoDB Atlas Organizations as Azure ARM resources with unified billing through Azure Marketplace. Create, update, list, or delete Atlas organizations using the Azure.ResourceManager.MongoDBAtlas SDK.
license: MIT
---
# Azure.ResourceManager.MongoDBAtlas SDK
Manage MongoDB Atlas Organizations as Azure ARM resources with unified billing through Azure Marketplace.
## Package Information
| Property | Value |
|----------|-------|
| Package | `Azure.ResourceManager.MongoDBAtlas` |
| Version | 1.0.0 (GA) |
| API Version | 2025-06-01 |
| Resource Type | `MongoDB.Atlas/organizations` |
| NuGet | [Azure.ResourceManager.MongoDBAtlas](https://www.nuget.org/packages/Azure.ResourceManager.MongoDBAtlas) |
## Installation
```bash
dotnet add package Azure.ResourceManager.MongoDBAtlas
dotnet add package Azure.Identity
dotnet add package Azure.ResourceManager
```
## Important Scope Limitation
This SDK manages **MongoDB Atlas Organizations as Azure ARM resources** for marketplace integration. It does NOT directly manage:
- Atlas clusters
- Databases
- Collections
- Users/roles
For cluster management, use the MongoDB Atlas API directly after creating the organization.
## Environment Variables
```bash
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_RESOURCE_GROUP=<your-resource-group> # Required: Azure resource group name
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
AZURE_TENANT_ID=<your-tenant-id> # For service principal auth (optional)
AZURE_CLIENT_ID=<your-client-id> # For service principal auth (optional)
AZURE_CLIENT_SECRET=<your-client-secret> # For service principal auth (optional)
```
## Authentication
```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MongoDBAtlas;
using Azure.ResourceManager.MongoDBAtlas.Models;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
```
## Core Types
| Type | Purpose |
|------|---------|
| `MongoDBAtlasOrganizationResource` | ARM resource representing an Atlas organization |
| `MongoDBAtlasOrganizationCollection` | Collection of organizations in a resource group |
| `MongoDBAtlasOrganizationData` | Data model for organization resource |
| `MongoDBAtlasOrganizationProperties` | Organization-specific properties |
| `MongoDBAtlasMarketplaceDetails` | Azure Marketplace subscription details |
| `MongoDBAtlasOfferDetails` | Marketplace offer configuration |
| `MongoDBAtlasUserDetails` | User information for the organization |
| `MongoDBAtlasPartnerProperties` | MongoDB-specific properties (org name, ID) |
## Workflows
### Get Organization Collection
```csharp
// Get resource group
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroup = await subscription.GetResourceGroupAsync("my-resource-group");
// Get organizations collection
MongoDBAtlasOrganizationCollection organizations =
resourceGroup.Value.GetMongoDBAtlasOrganizations();
```
### Create Organization
```csharp
var organizationName = "my-atlas-org";
var location = AzureLocation.EastUS2;
// Build organization data
var organizationData = new MongoDBAtlasOrganizationData(location)
{
Properties = new MongoDBAtlasOrganizationProperties(
marketplace: new MongoDBAtlasMarketplaceDetails(
subscriptionId: "your-azure-subscription-id",
offerDetails: new MongoDBAtlasOfferDetails(
publisherId: "mongodb",
offerId: "mongodb_atlas_azure_native_prod",
planId: "private_plan",
planName: "Pay as You Go (Free) (Private)",
termUnit: "P1M",
termId: "gmz7xq9ge3py"
)
),
user: new MongoDBAtlasUserDetails(
emailAddress: "[email protected]",
upn: "[email protected]"
)
{
FirstName = "Admin",
LastName = "User"
}
)
{
PartnerProperties = new MongoDBAtlasPartnerProperties
{
OrganizationName = organizationName
}
},
Tags = { ["Environment"] = "Production" }
};
// Create the organization (long-running operation)
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Completed,
organizationName,
organizationData
);
MongoDBAtlasOrganizationResource organization = operation.Value;
Console.WriteLine($"Created: {organization.Id}");
```
### Get Existing Organization
```csharp
// Option 1: From collection
MongoDBAtlasOrganizationResource org =
await organizations.GetAsync("my-atlas-org");
// Option 2: From resource identifier
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
subscriptionId: "subscription-id",
resourceGroupName: "my-resource-group",
organizationName: "my-atlas-org"
);
MongoDBAtlasOrganizationResource org2 =
armClient.GetMongoDBAtlasOrganizationResource(resourceId);
await org2.GetAsync(); // Fetch data
```
### List Organizations
```csharp
// List in resource group
await foreach (var org in organizations.GetAllAsync())
{
Console.WriteLine($"Org: {org.Data.Name}");
Console.WriteLine($" Location: {org.Data.Location}");
Console.WriteLine($" State: {org.Data.Properties?.ProvisioningState}");
}
// List across subscription
await foreach (var org in subscription.GetMongoDBAtlasOrganizationsAsync())
{
Console.WriteLine($"Org: {org.Data.Name} in {org.Data.Id}");
}
```
### Update Tags
```csharp
// Add a single tag
await organization.AddTagAsync("CostCenter", "12345");
// Replace all tags
await organization.SetTagsAsync(new Dictionary<string, string>
{
["Environment"] = "Production",
["Team"] = "Platform"
});
// Remove a tag
await organization.RemoveTagAsync("OldTag");
```
### Update Organization Properties
```csharp
var patch = new MongoDBAtlasOrganizationPatch
{
Tags = { ["UpdatedAt"] = DateTime.UtcNow.ToString("o") },
Properties = new MongoDBAtlasOrganizationUpdateProperties
{
// Update user details if needed
User = new MongoDBAtlasUserDetails(
emailAddress: "[email protected]",
upn: "[email protected]"
)
}
};
var updateOperation = await organization.UpdateAsync(
WaitUntil.Completed,
patch
);
```
### Delete Organization
```csharp
// Delete (long-running operation)
await organization.DeleteAsync(WaitUntil.Completed);
```
## Model Properties Reference
### MongoDBAtlasOrganizationProperties
| Property | Type | Description |
|----------|------|-------------|
| `Marketplace` | `MongoDBAtlasMarketplaceDetails` | Required. Marketplace subscription details |
| `User` | `MongoDBAtlasUserDetails` | Required. Organization admin user |
| `PartnerProperties` | `MongoDBAtlasPartnerProperties` | MongoDB-specific properties |
| `ProvisioningState` | `MongoDBAtlasResourceProvisioningState` | Read-only. Current provisioning state |
### MongoDBAtlasMarketplaceDetails
| Property | Type | Description |
|----------|------|-------------|
| `SubscriptionId` | `string` | Required. Azure subscription ID for billing |
| `OfferDetails` | `MongoDBAtlasOfferDetails` | Required. Marketplace offer configuration |
| `SubscriptionStatus` | `MarketplaceSubscriptionStatus` | Read-only. Subscription status |
### MongoDBAtlasOfferDetails
| Property | Type | Description |
|----------|------|-------------|
| `PublisherId` | `string` | Required. Publisher ID (typically "mongodb") |
| `OfferId` | `string` | Required. Offer ID |
| `PlanId` | `string` | Required. Plan ID |
| `PlanName` | `string` | Required. Display name of the plan |
| `TermUnit` | `string` | Required. Billing term unit (e.g., "P1M") |
| `TermId` | `string` | Required. Term identifier |
### MongoDBAtlasUserDetails
| Property | Type | Description |
|----------|------|-------------|
| `EmailAddress` | `string` | Required. User email address |
| `Upn` | `string` | Required. User principal name |
| `FirstName` | `string` | Optional. User first name |
| `LastName` | `string` | Optional. User last name |
### MongoDBAtlasPartnerProperties
| Property | Type | Description |
|----------|------|-------------|
| `OrganizationName` | `string` | Name of the MongoDB Atlas organization |
| `OrganizationId` | `string` | Read-only. MongoDB Atlas organization ID |
## Provisioning States
| State | Description |
|-------|-------------|
| `Succeeded` | Resource provisioned successfully |
| `Failed` | Provisioning failed |
| `Canceled` | Provisioning was canceled |
| `Provisioning` | Resource is being provisioned |
| `Updating` | Resource is being updated |
| `Deleting` | Resource is being deleted |
| `Accepted` | Request accepted, provisioning starting |
## Marketplace Subscription Status
| Status | Description |
|--------|-------------|
| `PendingFulfillmentStart` | Subscription pending activation |
| `Subscribed` | Active subscription |
| `Suspended` | Subscription suspended |
| `Unsubscribed` | Subscription canceled |
## Best Practices
### Use Async Methods
```csharp
// Prefer async for all operations
var org = await organizations.GetAsync("my-org");
await org.Value.AddTagAsync("key", "value");
```
### Handle Long-Running Operations
```csharp
// Wait for completion
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Completed, // Blocks until done
name,
data
);
// Or start and poll later
var operation = await organizations.CreateOrUpdateAsync(
WaitUntil.Started, // Returns immediately
name,
data
);
// Poll for completion
while (!operation.HasCompleted)
{
await Task.Delay(TimeSpan.FromSeconds(5));
await operation.UpdateStatusAsync();
}
```
### Check Provisioning State
```csharp
var org = await organizations.GetAsync("my-org");
if (org.Value.Data.Properties?.ProvisioningState ==
MongoDBAtlasResourceProvisioningState.Succeeded)
{
Console.WriteLine("Organization is ready");
}
```
### Use Resource Identifiers
```csharp
// Create identifier without API call
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
subscriptionId,
resourceGroupName,
organizationName
);
// Get resource handle (no data yet)
var orgResource = armClient.GetMongoDBAtlasOrganizationResource(resourceId);
// Fetch data when needed
var response = await orgResource.GetAsync();
```
## Common Errors
| Error | Cause | Solution |
|-------|-------|----------|
| `ResourceNotFound` | Organization doesn't exist | Verify name and resource group |
| `AuthorizationFailed` | Insufficient permissions | Check RBAC roles on resource group |
| `InvalidParameter` | Missing required properties | Ensure all required fields are set |
| `MarketplaceError` | Marketplace subscription issue | Verify offer details and subscription |
## Related Resources
- [Microsoft Learn: MongoDB Atlas on Azure](https://learn.microsoft.com/en-us/azure/partner-solutions/mongodb-atlas/)
- [API Reference](https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.mongodbatlas)
- [Azure SDK for .NET](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/mongodbatlas)