Azure CosmosDB (DocumentDB) SQL Container
This page shows how to write Terraform and Azure Resource Manager for CosmosDB (DocumentDB) SQL Container and write them securely.
azurerm_cosmosdb_sql_container (Terraform)
The SQL Container in CosmosDB (DocumentDB) can be configured in Terraform with the resource name azurerm_cosmosdb_sql_container
. The following sections describe 9 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_cosmosdb_sql_container" "users_access_cont" {
name = "Users"
resource_group_name = azurerm_cosmosdb_account.cdb.resource_group_name
account_name = azurerm_cosmosdb_account.cdb.name
database_name = azurerm_cosmosdb_sql_database.access_db.name
partition_key_path = "/Partition"
resource "azurerm_cosmosdb_sql_container" "non-usage_autoscale" {
name = "example-container"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
database_name = azurerm_cosmosdb_sql_database.example.name
partition_key_path = "/definition/id"
resource "azurerm_cosmosdb_sql_container" "coll_consumer_azm_1" {
name = "consumer_account_list"
resource_group_name = var.resource_group_name
account_name = azurerm_cosmosdb_account.consumer_cosmosdb_account.name
database_name = azurerm_cosmosdb_sql_database.db-consumer-azm.name
partition_key_path = "/listNameIdInsKey"
resource "azurerm_cosmosdb_sql_container" "coll_consumer_asp_1" {
name = "consumer_account_list"
resource_group_name = var.resource_group_name
account_name = azurerm_cosmosdb_account.consumer_cosmosdb_account.name
database_name = azurerm_cosmosdb_sql_database.db-consumer-asp.name
partition_key_path = "/listNameIdInsKey"
resource "azurerm_cosmosdb_sql_container" "non-usage_autoscale" {
name = "example-container"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
database_name = azurerm_cosmosdb_sql_database.example.name
partition_key_path = "/definition/id"
resource "azurerm_cosmosdb_sql_container" "container" {
name = var.container_name
resource_group_name = var.resource_group_name
account_name = var.db_account_name
database_name = var.db_name
partition_key_path = var.pkey_path
resource "azurerm_cosmosdb_sql_container" "container" {
resource_group_name = var.context.resource_group_name
account_name = var.service_settings.account_name
database_name = var.service_settings.database_name
resource "azurerm_cosmosdb_sql_container" "cosmosdb_container" {
for_each = {
for index, attribute in var.container_attributes: index => attribute
}
resource "azurerm_cosmosdb_sql_container" "wallet_users" {
name = "users"
resource_group_name = azurerm_cosmosdb_account.wallet_account.resource_group_name
account_name = azurerm_cosmosdb_account.wallet_account.name
database_name = azurerm_cosmosdb_sql_database.wallet_database.name
partition_key_path = "/id"
Parameters
-
account_name
required - string -
database_name
required - string -
default_ttl
optional computed - number -
id
optional computed - string -
name
required - string -
partition_key_path
optional - string -
partition_key_version
optional - number -
resource_group_name
required - string -
throughput
optional computed - number -
autoscale_settings
list block-
max_throughput
optional computed - number
-
-
indexing_policy
list block-
indexing_mode
optional - string -
composite_index
list block -
excluded_path
list block-
path
required - string
-
-
included_path
list block-
path
required - string
-
-
-
timeouts
single block -
unique_key
set block-
paths
required - set of string
-
Explanation in Terraform Registry
Manages a SQL Container within a Cosmos DB Account.
Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers (Azure Resource Manager)
The databaseAccounts/sqlDatabases/containers in Microsoft.DocumentDB can be configured in Azure Resource Manager with the resource name Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers
. 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 container 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.
conflictResolutionPolicy
optionalconflictResolutionPath
optional - stringThe conflict resolution path in the case of LastWriterWins mode.
conflictResolutionProcedure
optional - stringThe procedure to resolve conflicts in the case of custom mode.
mode
optional - stringIndicates the conflict resolution mode.
defaultTtl
optional - integerDefault time to live
id
required - stringName of the Cosmos DB SQL container
indexingPolicy
optionalautomatic
optional - booleanIndicates if the indexing policy is automatic
compositeIndexes
optional - arrayList of composite path list
excludedPaths
optional arraypath
optional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
includedPaths
optional arrayindexes
optional arraydataType
optional - stringThe datatype for which the indexing behavior is applied to.
kind
optional - stringIndicates the type of index.
precision
optional - integerThe precision of the index. -1 is maximum precision.
path
optional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
indexingMode
optional - stringIndicates the indexing mode.
spatialIndexes
optional arraypath
optional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
types
optional - arrayList of path's spatial type
partitionKey
optionalkind
optional - stringIndicates the kind of algorithm used for partitioning. For MultiHash, multiple partition keys (upto three maximum) are supported for container create.
paths
optional - arrayList of paths using which data within the container can be partitioned
version
optional - integerIndicates the version of the partition key definition
uniqueKeyPolicy
optionaluniqueKeys
optional arraypaths
optional - arrayList of paths must be unique for each document in the Azure Cosmos DB service
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) SQL Container?
Azure CosmosDB (DocumentDB) SQL Container 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) SQL Container?
For Terraform, the marsoffice/qeeps-terraform, gilyas/infracost and Lmartin43/Lmartin43 source code examples are useful. See the Terraform Example section for further details.