Skip to content

azurermCosmosdbSqlDatabase

Manages a SQL Database within a Cosmos DB Account.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const dataAzurermCosmosdbAccountExample =
  new azurerm.dataAzurermCosmosdbAccount.DataAzurermCosmosdbAccount(
    this,
    "example",
    {
      name: "tfex-cosmosdb-account",
      resource_group_name: "tfex-cosmosdb-account-rg",
    }
  );
const azurermCosmosdbSqlDatabaseExample =
  new azurerm.cosmosdbSqlDatabase.CosmosdbSqlDatabase(this, "example_1", {
    account_name: dataAzurermCosmosdbAccountExample.name,
    name: "tfex-cosmos-sql-db",
    resource_group_name: dataAzurermCosmosdbAccountExample.resourceGroupName,
    throughput: 400,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermCosmosdbSqlDatabaseExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the Cosmos DB SQL Database. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) The name of the resource group in which the Cosmos DB SQL Database is created. Changing this forces a new resource to be created.

  • accountName - (Required) The name of the Cosmos DB SQL Database to create the table within. Changing this forces a new resource to be created.

  • throughput - (Optional) The throughput of SQL database (RU/s). Must be set in increments of 100. The minimum value is 400. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. Do not set when azurermCosmosdbAccount is configured with enableServerless capability.

\~> Note: Throughput has a maximum value of 1000000 unless a higher limit is requested via Azure Support

  • autoscaleSettings - (Optional) An autoscaleSettings block as defined below. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply.

\~> Note: Switching between autoscale and manual throughput is not supported via Terraform and must be completed via the Azure Portal and refreshed.


An autoscaleSettings block supports the following:

  • maxThroughput - (Optional) The maximum throughput of the SQL database (RU/s). Must be between 1,000 and 1,000,000. Must be set in increments of 1,000. Conflicts with throughput.

Attributes Reference

The following attributes are exported:

  • id - The ID of the CosmosDB SQL Database.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the CosmosDB SQL Database.
  • update - (Defaults to 30 minutes) Used when updating the CosmosDB SQL Database.
  • read - (Defaults to 5 minutes) Used when retrieving the CosmosDB SQL Database.
  • delete - (Defaults to 30 minutes) Used when deleting the CosmosDB SQL Database.

Import

Cosmos SQL Database can be imported using the resourceId, e.g.

terraform import azurerm_cosmosdb_sql_database.db1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/sqlDatabases/db1