Azure CosmosDB (DocumentDB) SQL Database

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

azurerm_cosmosdb_sql_database (Terraform)

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

Example Usage from GitHub

cosmosdb_sql_database_test.tf#L84
resource "azurerm_cosmosdb_sql_database" "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
  autoscale_settings {
    max_throughput = 4000
cosmosdb_sql_database_test.tf#L84
resource "azurerm_cosmosdb_sql_database" "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
  autoscale_settings {
    max_throughput = 4000
main.tf#L1
resource "azurerm_cosmosdb_sql_database" "example" {
  name                = var.cosmosdb_db_name
  resource_group_name = var.cosmosdb_db_rg
  account_name        = var.cosmosdb_db_account_name
  throughput          = var.cosmosdb_db_throughput
main.tf#L43
resource "azurerm_cosmosdb_sql_database" "access_db" {
  name                = "access"
  resource_group_name = azurerm_cosmosdb_account.cdb.resource_group_name
  account_name        = azurerm_cosmosdb_account.cdb.name
}

main.tf#L1
resource "azurerm_cosmosdb_sql_database" "database" {
  name                = var.service_settings.name
  resource_group_name = var.context.resource_group_name
  account_name        = var.service_settings.account_name
  throughput          = var.service_settings.throughput

main.tf#L42
resource "azurerm_cosmosdb_sql_database" "sqldb" {
  name                = var.sql_database_name
  resource_group_name = var.rg.name
  account_name        = azurerm_cosmosdb_account.name
  throughput          = 400
}
main.tf#L1
resource "azurerm_cosmosdb_sql_database" "database" {
  name                = var.service_settings.name
  resource_group_name = var.context.resource_group_name
  account_name        = var.service_settings.account_name

  autoscale_settings {
main.tf#L19
resource "azurerm_cosmosdb_sql_database" "db" {
  name                = var.db_name
  resource_group_name = var.resource_group_name
  account_name        = var.account_name
  throughput          = var.privisioned_throughput
}
main.tf#L34
resource "azurerm_cosmosdb_sql_database" "example" {
  name                = "cosmos-db"
  resource_group_name = azurerm_resource_group.example.name
  account_name        = azurerm_cosmosdb_account.db.name
  throughput          = 400
}
main.tf#L1
resource "azurerm_cosmosdb_sql_database" "database" {
  name                = var.name
  resource_group_name = var.resource_group_name
  account_name        = var.account_name
  throughput          = var.throughput

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 SQL Database within a Cosmos DB Account.

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

The databaseAccounts/sqlDatabases in Microsoft.DocumentDB can be configured in Azure Resource Manager with the resource name Microsoft.DocumentDB/databaseAccounts/sqlDatabases. 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 SQL 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) SQL Database?

Azure CosmosDB (DocumentDB) SQL 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) SQL Database?

For Terraform, the gilyas/infracost, infracost/infracost and christian1607/Terraform source code examples are useful. See the Terraform Example section for further details.