title | description | author | ms.service | ms.subservice | ms.custom | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|
Create and manage Azure Cosmos DB with terraform |
Use terraform to create and configure Azure Cosmos DB for NoSQL |
ginsiucheng |
azure-cosmos-db |
nosql |
devx-track-terraform |
how-to |
09/16/2022 |
mjbrown |
[!INCLUDENoSQL]
In this article, you learn how to use terraform to deploy and manage your Azure Cosmos DB accounts, databases, and containers.
This article shows terraform samples for NoSQL accounts.
Important
- Account names are limited to 44 characters, all lowercase.
- To change the throughput (RU/s) values, redeploy the terraform file with updated RU/s.
- When you add or remove locations to an Azure Cosmos account, you can't simultaneously modify other properties. These operations must be done separately.
- To provision throughput at the database level and share across all containers, apply the throughput values to the database options property.
To create any of the Azure Cosmos DB resources below, copy the example into a new terraform file (main.tf) or alternatively, have two separate files for resources (main.tf) and variables (variables.tf). Be sure to include the azurerm provider either in the main terraform file or split out to a separate providers file. All examples can be found on the terraform samples repository.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/providers.tf":::
Create an Azure Cosmos account in two regions with options for consistency and failover, with database and container configured for autoscale throughput that has most index policy options enabled.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/variables.tf":::
Create an Azure Cosmos account in one region with a container with Analytical TTL enabled and options for manual or autoscale throughput.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-analyticalstore/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-analyticalstore/variables.tf":::
Create an Azure Cosmos account in two regions with options for consistency and failover, with database and container configured for standard throughput that has most policy options enabled.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/variables.tf":::
Create an Azure Cosmos account, database and container with a stored procedure, trigger, and user-defined function.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-serverside-functionality/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-serverside-functionality/variables.tf":::
Create an Azure Cosmos account, a natively maintained Role Definition, and a natively maintained Role Assignment for a Microsoft Entra identity.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-aad-rbac/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-aad-rbac/variables.tf":::
Create a free-tier Azure Cosmos account and a database with shared throughput that can be shared with up to 25 containers.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-free-tier/main.tf":::
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-free-tier/variables.tf":::
Here are some more resources: