Azure CosmosDB (DocumentDB) Mongo Database

This page shows how to write Terraform and Azure Resource Manager for CosmosDB (DocumentDB) Mongo Database and write them securely.

azurerm_cosmosdb_mongo_database (Terraform)

The Mongo Database in CosmosDB (DocumentDB) can be configured in Terraform with the resource name azurerm_cosmosdb_mongo_database. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

cosmosmongo.tf#L32
resource "azurerm_cosmosdb_mongo_database" "mydb" {
    name                = "mydb"
    resource_group_name = data.azurerm_resource_group.GymResourceGroup.name
    account_name        = azurerm_cosmosdb_account.gym_cosmos_account.name
    throughput          = 400
}
azure.tf#L66
resource "azurerm_cosmosdb_mongo_database" "ngc_sessions" {
  name                = "SessionsDb"
  resource_group_name = azurerm_resource_group.ngc.name
  account_name        = azurerm_cosmosdb_account.ngc.name
}

cosmosdb_mongo_database_test.tf#L84
resource "azurerm_cosmosdb_mongo_database" "non-usage_autoscale" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  autoscale_settings {
    max_throughput = 4000
cosmosdb_mongo_collection_test.tf#L84
resource "azurerm_cosmosdb_mongo_database" "non-usage_autoscale" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  autoscale_settings {
    max_throughput = 4000
cosmosdb_mongo_database_test.tf#L84
resource "azurerm_cosmosdb_mongo_database" "non-usage_autoscale" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  autoscale_settings {
    max_throughput = 4000
cosmosdb_mongo_collection_test.tf#L84
resource "azurerm_cosmosdb_mongo_database" "non-usage_autoscale" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  autoscale_settings {
    max_throughput = 4000
mongo-db.tf#L1
resource "azurerm_cosmosdb_mongo_database" "post-office-mongo-db" {
  name                = "mongo-db"
  location            = azurerm_resource_group.post-office-rg.location
  resource_group_name = azurerm_resource_group.post-office-rg.name
  throughput          = 400
}
main.tf#L7
resource "azurerm_cosmosdb_mongo_database" "this" {
  account_name        = var.account_name
  name                = var.name
  resource_group_name = var.resource_group_name
  throughput          = var.throughput

main.tf#L38
resource "azurerm_cosmosdb_mongo_database" "mongodb" {
  name                = "cosmosmongodb"
  resource_group_name = azurerm_cosmosdb_account.acc.resource_group_name
  account_name        = azurerm_cosmosdb_account.acc.name
  throughput          = 400
}
mongo_database.tf#L4
resource "azurerm_cosmosdb_mongo_database" "database" {
  name                = var.settings.name
  resource_group_name = var.resource_group_name
  account_name        = var.cosmosdb_account_name
  throughput          = try(var.settings.throughput, null)

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Mongo Database within a Cosmos DB Account.

Microsoft.DocumentDB/databaseAccounts/mongodbDatabases (Azure Resource Manager)

The databaseAccounts/mongodbDatabases in Microsoft.DocumentDB can be configured in Azure Resource Manager with the resource name Microsoft.DocumentDB/databaseAccounts/mongodbDatabases. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

  • apiVersion required - string
  • location optional - string

    The location of the resource group to which the resource belongs.

  • name required - string

    Cosmos DB database name.

  • properties required
      • options optional
          • autoscaleSettings optional
              • maxThroughput optional - integer

                Represents maximum throughput, the resource can scale up to.

          • throughput optional - integer

            Request Units per second. For example, "throughput": 10000.

      • resource required
          • id required - string

            Name of the Cosmos DB MongoDB database

  • tags optional - string

    Tags are a list of key-value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters. For example, the default experience for a template type is set with "defaultExperience": "Cassandra". Current "defaultExperience" values also include "Table", "Graph", "DocumentDB", and "MongoDB".

  • type required - string

Frequently asked questions

What is Azure CosmosDB (DocumentDB) Mongo Database?

Azure CosmosDB (DocumentDB) Mongo Database is a resource for CosmosDB (DocumentDB) of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure CosmosDB (DocumentDB) Mongo Database?

For Terraform, the TELLAI/Gym-project-MERN, cloud-native-conference/Infrastructure and gilyas/infracost source code examples are useful. See the Terraform Example section for further details.