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
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
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
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
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
}
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
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
}
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 {
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
}
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
}
resource "azurerm_cosmosdb_sql_database" "database" {
name = var.name
resource_group_name = var.resource_group_name
account_name = var.account_name
throughput = var.throughput
Parameters
-
account_name
required - string -
id
optional computed - string -
name
required - string -
resource_group_name
required - string -
throughput
optional computed - number -
autoscale_settings
list block-
max_throughput
optional computed - number
-
-
timeouts
single block
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 - stringlocation
optional - stringThe location of the resource group to which the resource belongs.
name
required - stringCosmos DB database 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
requiredid
required - stringName of the Cosmos DB SQL database
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 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.