Skip to content

azurermCosmosdbSqlContainer

Manages a SQL Container 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: "example-acsd",
    resource_group_name: dataAzurermCosmosdbAccountExample.resourceGroupName,
  });
/*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");
const azurermCosmosdbSqlContainerExample =
  new azurerm.cosmosdbSqlContainer.CosmosdbSqlContainer(this, "example_2", {
    account_name: dataAzurermCosmosdbAccountExample.name,
    database_name: azurermCosmosdbSqlDatabaseExample.name,
    indexing_policy: [
      {
        excluded_path: [
          {
            path: "/excluded/?",
          },
        ],
        included_path: [
          {
            path: "/*",
          },
          {
            path: "/included/?",
          },
        ],
        indexing_mode: "consistent",
      },
    ],
    name: "example-container",
    partition_key_path: "/definition/id",
    partition_key_version: 1,
    resource_group_name: dataAzurermCosmosdbAccountExample.resourceGroupName,
    throughput: 400,
    unique_key: [
      {
        paths: ["/definition/idlong", "/definition/idshort"],
      },
    ],
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermCosmosdbSqlContainerExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

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

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

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

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

  • partitionKeyPath - (Required) Define a partition key. Changing this forces a new resource to be created.

  • partitionKeyVersion - (Optional) Define a partition key version. Changing this forces a new resource to be created. Possible values are 1and 2. This should be set to 2 in order to use large partition keys.

  • uniqueKey - (Optional) One or more uniqueKey blocks as defined below. Changing this forces a new resource to be created.

  • throughput - (Optional) The throughput of SQL container (RU/s). Must be set in increments of 100. The minimum value is 400. This must be set upon container creation otherwise it cannot be updated without a manual terraform destroy-apply.

  • 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. Requires partitionKeyPath to be set.

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

  • indexingPolicy - (Optional) An indexingPolicy block as defined below.

  • defaultTtl - (Optional) The default time to live of SQL container. If missing, items are not expired automatically. If present and the value is set to 1, it is equal to infinity, and items don’t expire by default. If present and the value is set to some number n – items will expire n seconds after their last modified time.

  • analyticalStorageTtl - (Optional) The default time to live of Analytical Storage for this SQL container. If present and the value is set to 1, it is equal to infinity, and items don’t expire by default. If present and the value is set to some number n – items will expire n seconds after their last modified time.

  • conflictResolutionPolicy - (Optional) A conflictResolutionPolicy blocks as defined below. Changing this forces a new resource to be created.


An autoscaleSettings block supports the following:

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

A uniqueKey block supports the following:

  • paths - (Required) A list of paths to use for this unique key. Changing this forces a new resource to be created.

An indexingPolicy block supports the following:

  • indexingMode - (Optional) Indicates the indexing mode. Possible values include: consistent and none. Defaults to consistent.

  • includedPath - (Optional) One or more includedPath blocks as defined below. Either includedPath or excludedPath must contain the path /*

  • excludedPath - (Optional) One or more excludedPath blocks as defined below. Either includedPath or excludedPath must contain the path /*

  • compositeIndex - (Optional) One or more compositeIndex blocks as defined below.

  • spatialIndex - (Optional) One or more spatialIndex blocks as defined below.


A spatialIndex block supports the following:

  • path - (Required) Path for which the indexing behaviour applies to. According to the service design, all spatial types including lineString, multiPolygon, point, and polygon will be applied to the path.

An includedPath block supports the following:

  • path - (Required) Path for which the indexing behaviour applies to.

An excludedPath block supports the following:

  • path - (Required) Path that is excluded from indexing.

A compositeIndex block supports the following:

  • index - (Required) One or more index blocks as defined below.

An index block supports the following:

  • path - (Required) Path for which the indexing behaviour applies to.

  • order - (Required) Order of the index. Possible values are ascending or descending.


A conflictResolutionPolicy block supports the following:

  • mode - (Required) Indicates the conflict resolution mode. Possible values include: lastWriterWins, custom.

  • conflictResolutionPath - (Optional) The conflict resolution path in the case of lastWriterWins mode.

  • conflictResolutionProcedure - (Optional) The procedure to resolve conflicts in the case of custom mode.

Attributes Reference

The following attributes are exported:

  • id - The ID of the CosmosDB SQL Container.

A spatialIndex block exports the following:

  • types - A set of spatial types of the path.

Timeouts

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

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

Import

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

terraform import azurerm_cosmosdb_sql_container.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DocumentDB/databaseAccounts/account1/sqlDatabases/database1/containers/container1