Azure CosmosDB (DocumentDB) Mongo Collection
This page shows how to write Terraform and Azure Resource Manager for CosmosDB (DocumentDB) Mongo Collection and write them securely.
azurerm_cosmosdb_mongo_collection (Terraform)
The Mongo Collection in CosmosDB (DocumentDB) can be configured in Terraform with the resource name azurerm_cosmosdb_mongo_collection
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_cosmosdb_mongo_collection" "ngc" {
name = "Sessions"
resource_group_name = azurerm_resource_group.ngc.name
account_name = azurerm_cosmosdb_account.ngc.name
database_name = azurerm_cosmosdb_mongo_database.ngc_sessions.name
resource "azurerm_cosmosdb_mongo_collection" "mongo_collection_static" {
name = var.collection_name
resource_group_name = var.resource_group_name
account_name = var.account_name
database_name = var.db_name
default_ttl_seconds = var.default_ttl_seconds
resource "azurerm_cosmosdb_mongo_collection" "non-usage_autoscale" {
name = "tfex-cosmos-mongo-db"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
database_name = azurerm_cosmosdb_mongo_database.non-usage_autoscale.name
resource "azurerm_cosmosdb_mongo_collection" "non-usage_autoscale" {
name = "tfex-cosmos-mongo-db"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
database_name = azurerm_cosmosdb_mongo_database.non-usage_autoscale.name
resource "azurerm_cosmosdb_mongo_collection" "questions" {
name = "questions"
resource_group_name = azurerm_resource_group.rg.name
account_name = azurerm_cosmosdb_account.default.name
database_name = azurerm_cosmosdb_mongo_database.default.name
resource "azurerm_cosmosdb_mongo_collection" "collection" {
name = var.settings.name
resource_group_name = var.resource_group_name
account_name = var.cosmosdb_account_name
database_name = var.database_name
shard_key = var.settings.shard_key
resource "azurerm_cosmosdb_mongo_collection" "event_collection" {
name = "events"
resource_group_name = azurerm_resource_group.rg.name
account_name = azurerm_cosmosdb_account.db_account.name
database_name = azurerm_cosmosdb_mongo_database.mongo_db.name
resource "azurerm_cosmosdb_mongo_collection" "collection" {
name = var.settings.name
resource_group_name = var.resource_group_name
account_name = var.cosmosdb_account_name
database_name = var.database_name
shard_key = var.settings.shard_key
resource "azurerm_cosmosdb_mongo_collection" "collection" {
name = var.settings.name
resource_group_name = var.resource_group_name
account_name = var.cosmosdb_account_name
database_name = var.database_name
shard_key = var.settings.shard_key
resource "azurerm_cosmosdb_mongo_collection" "mongodb" {
count = length(var.collections)
name = var.collections[count.index].name
default_ttl_seconds = var.collections[count.index].default_ttl_seconds
Parameters
-
account_name
required - string -
database_name
required - string -
default_ttl_seconds
optional - number -
id
optional computed - string -
name
required - string -
resource_group_name
required - string -
shard_key
optional - string -
system_indexes
optional computed - list of object -
throughput
optional computed - number -
autoscale_settings
list block-
max_throughput
optional computed - number
-
-
index
set block -
timeouts
single block
Explanation in Terraform Registry
Manages a Mongo Collection within a Cosmos DB Account.
Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/collections (Azure Resource Manager)
The databaseAccounts/mongodbDatabases/collections in Microsoft.DocumentDB can be configured in Azure Resource Manager with the resource name Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/collections
. 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 - stringlocation
optional - stringThe location of the resource group to which the resource belongs.
name
required - stringCosmos DB collection name.
properties
requiredoptions
optionalautoscaleSettings
optionalmaxThroughput
optional - integerRepresents maximum throughput, the resource can scale up to.
throughput
optional - integerRequest Units per second. For example, "throughput": 10000.
resource
requiredanalyticalStorageTtl
optional - integerAnalytical TTL.
id
required - stringName of the Cosmos DB MongoDB collection
indexes
optional arraykey
optionalkeys
optional - arrayList of keys for each MongoDB collection in the Azure Cosmos DB service
options
optionalexpireAfterSeconds
optional - integerExpire after seconds
unique
optional - booleanIs unique or not
shardKey
optional - stringThe shard key and partition kind pair, only support "Hash" partition kind
tags
optional - stringTags 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 Collection?
Azure CosmosDB (DocumentDB) Mongo Collection 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 Collection?
For Terraform, the cloud-native-conference/Infrastructure, marvin-heiden/sendungsverfolgung and gilyas/infracost source code examples are useful. See the Terraform Example section for further details.