azure-resource-manager-cosmosdb-dotnet

Azure Resource Manager SDK for Cosmos DB in .NET.

31,392 stars
Complexity: easy

About this skill

This skill enables an AI agent to provision, configure, and manage Azure Cosmos DB resources by interacting with the Azure Resource Manager (ARM) through a dedicated .NET SDK (`Azure.ResourceManager.CosmosDB`). It provides programmatic access to the *management plane* of Azure Cosmos DB, allowing an agent to create and configure Cosmos DB accounts, databases, and containers, manage throughput settings, and control Role-Based Access Control (RBAC). Crucially, it is distinct from data plane operations (like CRUD operations on documents, queries, or stored procedure execution), which would require a separate data plane SDK (e.g., `Microsoft.Azure.Cosmos`). This skill empowers AI agents to handle the infrastructure and configuration aspects of Cosmos DB, making it ideal for automation and cloud resource orchestration.

Best use case

Automating Azure Cosmos DB infrastructure setup; Dynamically provisioning Cosmos DB resources (accounts, databases, containers) based on application or system requirements; Configuring and scaling throughput for existing Cosmos DB resources; Managing security and access permissions (RBAC) for Cosmos DB; Integrating Cosmos DB infrastructure management into larger DevOps or infrastructure-as-code workflows controlled by an AI agent.

Azure Resource Manager SDK for Cosmos DB in .NET.

Successful creation, update, or deletion of Azure Cosmos DB accounts, databases, or containers; Configured throughput settings, regional replication, or RBAC rules for Cosmos DB; Programmatic and automated management of Cosmos DB infrastructure via Azure Resource Manager; Reduced manual effort in provisioning and maintaining Cosmos DB resources.

Practical example

Example input

Provision a new Azure Cosmos DB account named 'my-application-db' in the 'East US' region using the SQL API. Within this account, create a database named 'user-data' and a container named 'profiles' with a dedicated throughput of 400 RU/s. Ensure it's ready for use.

Example output

Successfully provisioned Azure Cosmos DB account 'my-application-db' in 'East US' with SQL API. Database 'user-data' and container 'profiles' (400 RU/s) created. The Cosmos DB infrastructure setup is complete and ready for data plane operations.

When to use this skill

  • When an AI agent needs to create new Azure Cosmos DB accounts, databases, or containers; When an AI agent needs to modify the configuration (e.g., throughput, regions, consistency policies) of existing Cosmos DB resources; When an AI agent needs to set up or manage access permissions (RBAC) for Cosmos DB users or services; As a component within a larger AI-driven automation pipeline for cloud resource management.

When not to use this skill

  • When the task involves interacting with data *inside* Cosmos DB (e.g., adding documents, querying data, executing stored procedures). For data operations, a data plane SDK like `Microsoft.Azure.Cosmos` is required; When managing Azure resources other than Cosmos DB (requires different ARM SDKs); When a non-.NET programming environment is preferred or mandated for resource management.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/azure-resource-manager-cosmosdb-dotnet/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/azure-resource-manager-cosmosdb-dotnet/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/azure-resource-manager-cosmosdb-dotnet/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How azure-resource-manager-cosmosdb-dotnet Compares

Feature / Agentazure-resource-manager-cosmosdb-dotnetStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

Azure Resource Manager SDK for Cosmos DB in .NET.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Azure.ResourceManager.CosmosDB (.NET)

Management plane SDK for provisioning and managing Azure Cosmos DB resources via Azure Resource Manager.

> **⚠️ Management vs Data Plane**
> - **This SDK (Azure.ResourceManager.CosmosDB)**: Create accounts, databases, containers, configure throughput, manage RBAC
> - **Data Plane SDK (Microsoft.Azure.Cosmos)**: CRUD operations on documents, queries, stored procedures execution

## Installation

```bash
dotnet add package Azure.ResourceManager.CosmosDB
dotnet add package Azure.Identity
```

**Current Versions**: Stable v1.4.0, Preview v1.4.0-beta.13

## Environment Variables

```bash
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
# For service principal auth (optional)
AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_CLIENT_SECRET=<client-secret>
```

## Authentication

```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.CosmosDB;

// Always use DefaultAzureCredential
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);

// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
    new ResourceIdentifier($"/subscriptions/{subscriptionId}"));
```

## Resource Hierarchy

```
ArmClient
└── SubscriptionResource
    └── ResourceGroupResource
        └── CosmosDBAccountResource
            ├── CosmosDBSqlDatabaseResource
            │   └── CosmosDBSqlContainerResource
            │       ├── CosmosDBSqlStoredProcedureResource
            │       ├── CosmosDBSqlTriggerResource
            │       └── CosmosDBSqlUserDefinedFunctionResource
            ├── CassandraKeyspaceResource
            ├── GremlinDatabaseResource
            ├── MongoDBDatabaseResource
            └── CosmosDBTableResource
```

## Core Workflow

### 1. Create Cosmos DB Account

```csharp
using Azure.ResourceManager.CosmosDB;
using Azure.ResourceManager.CosmosDB.Models;

// Get resource group
var resourceGroup = await subscription
    .GetResourceGroupAsync("my-resource-group");

// Define account
var accountData = new CosmosDBAccountCreateOrUpdateContent(
    location: AzureLocation.EastUS,
    locations: new[]
    {
        new CosmosDBAccountLocation
        {
            LocationName = AzureLocation.EastUS,
            FailoverPriority = 0,
            IsZoneRedundant = false
        }
    })
{
    Kind = CosmosDBAccountKind.GlobalDocumentDB,
    ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.Session),
    EnableAutomaticFailover = true
};

// Create account (long-running operation)
var accountCollection = resourceGroup.Value.GetCosmosDBAccounts();
var operation = await accountCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-cosmos-account",
    accountData);

CosmosDBAccountResource account = operation.Value;
```

### 2. Create SQL Database

```csharp
var databaseData = new CosmosDBSqlDatabaseCreateOrUpdateContent(
    new CosmosDBSqlDatabaseResourceInfo("my-database"));

var databaseCollection = account.GetCosmosDBSqlDatabases();
var dbOperation = await databaseCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-database",
    databaseData);

CosmosDBSqlDatabaseResource database = dbOperation.Value;
```

### 3. Create SQL Container

```csharp
var containerData = new CosmosDBSqlContainerCreateOrUpdateContent(
    new CosmosDBSqlContainerResourceInfo("my-container")
    {
        PartitionKey = new CosmosDBContainerPartitionKey
        {
            Paths = { "/partitionKey" },
            Kind = CosmosDBPartitionKind.Hash
        },
        IndexingPolicy = new CosmosDBIndexingPolicy
        {
            Automatic = true,
            IndexingMode = CosmosDBIndexingMode.Consistent
        },
        DefaultTtl = 86400 // 24 hours
    });

var containerCollection = database.GetCosmosDBSqlContainers();
var containerOperation = await containerCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-container",
    containerData);

CosmosDBSqlContainerResource container = containerOperation.Value;
```

### 4. Configure Throughput

```csharp
// Manual throughput
var throughputData = new ThroughputSettingsUpdateData(
    new ThroughputSettingsResourceInfo
    {
        Throughput = 400
    });

// Autoscale throughput
var autoscaleData = new ThroughputSettingsUpdateData(
    new ThroughputSettingsResourceInfo
    {
        AutoscaleSettings = new AutoscaleSettingsResourceInfo
        {
            MaxThroughput = 4000
        }
    });

// Apply to database
await database.CreateOrUpdateCosmosDBSqlDatabaseThroughputAsync(
    WaitUntil.Completed,
    throughputData);
```

### 5. Get Connection Information

```csharp
// Get keys
var keys = await account.GetKeysAsync();
Console.WriteLine($"Primary Key: {keys.Value.PrimaryMasterKey}");

// Get connection strings
var connectionStrings = await account.GetConnectionStringsAsync();
foreach (var cs in connectionStrings.Value.ConnectionStrings)
{
    Console.WriteLine($"{cs.Description}: {cs.ConnectionString}");
}
```

## Key Types Reference

| Type | Purpose |
|------|---------|
| `ArmClient` | Entry point for all ARM operations |
| `CosmosDBAccountResource` | Represents a Cosmos DB account |
| `CosmosDBAccountCollection` | Collection for account CRUD |
| `CosmosDBSqlDatabaseResource` | SQL API database |
| `CosmosDBSqlContainerResource` | SQL API container |
| `CosmosDBAccountCreateOrUpdateContent` | Account creation payload |
| `CosmosDBSqlDatabaseCreateOrUpdateContent` | Database creation payload |
| `CosmosDBSqlContainerCreateOrUpdateContent` | Container creation payload |
| `ThroughputSettingsUpdateData` | Throughput configuration |

## Best Practices

1. **Use `WaitUntil.Completed`** for operations that must finish before proceeding
2. **Use `WaitUntil.Started`** when you want to poll manually or run operations in parallel
3. **Always use `DefaultAzureCredential`** — never hardcode keys
4. **Handle `RequestFailedException`** for ARM API errors
5. **Use `CreateOrUpdateAsync`** for idempotent operations
6. **Navigate hierarchy** via `Get*` methods (e.g., `account.GetCosmosDBSqlDatabases()`)

## Error Handling

```csharp
using Azure;

try
{
    var operation = await accountCollection.CreateOrUpdateAsync(
        WaitUntil.Completed, accountName, accountData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
    Console.WriteLine("Account already exists");
}
catch (RequestFailedException ex)
{
    Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}");
}
```

## Reference Files

| File | When to Read |
|------|--------------|
| references/account-management.md | Account CRUD, failover, keys, connection strings, networking |
| references/sql-resources.md | SQL databases, containers, stored procedures, triggers, UDFs |
| references/throughput.md | Manual/autoscale throughput, migration between modes |

## Related SDKs

| SDK | Purpose | Install |
|-----|---------|---------|
| `Microsoft.Azure.Cosmos` | Data plane (document CRUD, queries) | `dotnet add package Microsoft.Azure.Cosmos` |
| `Azure.ResourceManager.CosmosDB` | Management plane (this SDK) | `dotnet add package Azure.ResourceManager.CosmosDB` |

## When to Use
This skill is applicable to execute the workflow or actions described in the overview.

Related Skills

azure-resource-manager-sql-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure Resource Manager SDK for Azure SQL in .NET.

Cloud ManagementClaudeGitHub CopilotCursor

azure-resource-manager-redis-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure Resource Manager SDK for Redis in .NET.

Cloud ManagementClaude

azure-resource-manager-postgresql-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure PostgreSQL Flexible Server SDK for .NET. Database management for PostgreSQL Flexible Server deployments.

Cloud ManagementClaude

azure-resource-manager-mysql-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure MySQL Flexible Server SDK for .NET. Database management for MySQL Flexible Server deployments.

Cloud ManagementClaude

azure-monitor-query-py

31392
from sickn33/antigravity-awesome-skills

Azure Monitor Query SDK for Python. Use for querying Log Analytics workspaces and Azure Monitor metrics.

Cloud ManagementClaude

azure-mgmt-weightsandbiases-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure Weights & Biases SDK for .NET. ML experiment tracking and model management via Azure Marketplace. Use for creating W&B instances, managing SSO, marketplace integration, and ML observability.

Cloud ManagementClaude

azure-mgmt-botservice-py

31392
from sickn33/antigravity-awesome-skills

Azure Bot Service Management SDK for Python. Use for creating, managing, and configuring Azure Bot Service resources.

Cloud ManagementClaudeChatGPTGemini

azure-mgmt-botservice-dotnet

31392
from sickn33/antigravity-awesome-skills

Azure Resource Manager SDK for Bot Service in .NET. Management plane operations for creating and managing Azure Bot resources, channels (Teams, DirectLine, Slack), and connection settings.

Cloud ManagementClaude

azure-mgmt-apicenter-py

31392
from sickn33/antigravity-awesome-skills

Azure API Center Management SDK for Python. Use for managing API inventory, metadata, and governance across your organization.

Cloud ManagementClaude

azure-containerregistry-py

31392
from sickn33/antigravity-awesome-skills

Azure Container Registry SDK for Python. Use for managing container images, artifacts, and repositories.

Cloud ManagementClaude

azure-keyvault-certificates-rust

31355
from sickn33/antigravity-awesome-skills

Azure Key Vault Certificates SDK for Rust. Use for creating, importing, and managing certificates.

Cloud ManagementClaude

cost-optimization

31392
from sickn33/antigravity-awesome-skills

Strategies and patterns for optimizing cloud costs across AWS, Azure, and GCP.

Cloud ManagementClaude