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_namerequired - string -
database_namerequired - string -
default_ttl_secondsoptional - number -
idoptional computed - string -
namerequired - string -
resource_group_namerequired - string -
shard_keyoptional - string -
system_indexesoptional computed - list of object -
throughputoptional computed - number -
autoscale_settingslist block-
max_throughputoptional computed - number
-
-
indexset block -
timeoutssingle 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
apiVersionrequired - stringlocationoptional - stringThe location of the resource group to which the resource belongs.
namerequired - stringCosmos DB collection name.
propertiesrequiredoptionsoptionalautoscaleSettingsoptionalmaxThroughputoptional - integerRepresents maximum throughput, the resource can scale up to.
throughputoptional - integerRequest Units per second. For example, "throughput": 10000.
resourcerequiredanalyticalStorageTtloptional - integerAnalytical TTL.
idrequired - stringName of the Cosmos DB MongoDB collection
indexesoptional arraykeyoptionalkeysoptional - arrayList of keys for each MongoDB collection in the Azure Cosmos DB service
optionsoptionalexpireAfterSecondsoptional - integerExpire after seconds
uniqueoptional - booleanIs unique or not
shardKeyoptional - stringThe shard key and partition kind pair, only support "Hash" partition kind
tagsoptional - 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".
typerequired - 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.