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_namerequired - string -
database_namerequired - string -
default_ttloptional computed - number -
idoptional computed - string -
namerequired - string -
partition_key_pathoptional - string -
partition_key_versionoptional - number -
resource_group_namerequired - string -
throughputoptional computed - number -
autoscale_settingslist block-
max_throughputoptional computed - number
-
-
indexing_policylist block-
indexing_modeoptional - string -
composite_indexlist block -
excluded_pathlist block-
pathrequired - string
-
-
included_pathlist block-
pathrequired - string
-
-
-
timeoutssingle block -
unique_keyset block-
pathsrequired - 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
apiVersionrequired - stringlocationoptional - stringThe location of the resource group to which the resource belongs.
namerequired - stringCosmos DB container name.
propertiesrequiredoptionsoptionalautoscaleSettingsoptionalmaxThroughputoptional - integerRepresents maximum throughput, the resource can scale up to.
throughputoptional - integerRequest Units per second. For example, "throughput": 10000.
resourcerequiredanalyticalStorageTtloptional - integerAnalytical TTL.
conflictResolutionPolicyoptionalconflictResolutionPathoptional - stringThe conflict resolution path in the case of LastWriterWins mode.
conflictResolutionProcedureoptional - stringThe procedure to resolve conflicts in the case of custom mode.
modeoptional - stringIndicates the conflict resolution mode.
defaultTtloptional - integerDefault time to live
idrequired - stringName of the Cosmos DB SQL container
indexingPolicyoptionalautomaticoptional - booleanIndicates if the indexing policy is automatic
compositeIndexesoptional - arrayList of composite path list
excludedPathsoptional arraypathoptional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
includedPathsoptional arrayindexesoptional arraydataTypeoptional - stringThe datatype for which the indexing behavior is applied to.
kindoptional - stringIndicates the type of index.
precisionoptional - integerThe precision of the index. -1 is maximum precision.
pathoptional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
indexingModeoptional - stringIndicates the indexing mode.
spatialIndexesoptional arraypathoptional - stringThe path for which the indexing behavior applies to. Index paths typically start with root and end with wildcard (/path/*)
typesoptional - arrayList of path's spatial type
partitionKeyoptionalkindoptional - stringIndicates the kind of algorithm used for partitioning. For MultiHash, multiple partition keys (upto three maximum) are supported for container create.
pathsoptional - arrayList of paths using which data within the container can be partitioned
versionoptional - integerIndicates the version of the partition key definition
uniqueKeyPolicyoptionaluniqueKeysoptional arraypathsoptional - arrayList of paths must be unique for each document in the Azure Cosmos DB service
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) 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.