title | description | author | ms.author | tags | ms.custom | ms.service | ms.subservice | ms.topic | ms.date |
---|---|---|---|---|---|---|---|---|---|
Quickstart - Create an Azure Cosmos DB database and container using Terraform |
Quickstart showing how to an Azure Cosmos DB database and a container using Terraform |
ginsiucheng |
mjbrown |
azure-resource-manager, terraform |
devx-track-terraform |
azure-cosmos-db |
nosql |
quickstart |
09/22/2022 |
[!INCLUDENoSQL]
Azure Cosmos DB is Microsoft’s fast NoSQL database with open APIs for any scale. You can use Azure Cosmos DB to quickly create and query key/value databases, document databases, and graph databases. Without a credit card or an Azure subscription, you can set up a free Try Azure Cosmos DB account. This quickstart focuses on the process of deployments via Terraform to create an Azure Cosmos database and a container within that database. You can later store data in this container.
An Azure subscription or free Azure Cosmos DB trial account
- [!INCLUDE quickstarts-free-trial-note]
Terraform should be installed on your local computer. Installation instructions can be found here.
The Terraform files used in this quickstart can be found on the terraform samples repository. Create the below three files: providers.tf, main.tf and variables.tf. Variables can be set in command line or alternatively with a terraforms.tfvars file.
:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/providers.tf":::
:::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":::
Three Cosmos DB resources are defined in the main terraform file.
-
Microsoft.DocumentDB/databaseAccounts: Create an Azure Cosmos account.
-
Microsoft.DocumentDB/databaseAccounts/sqlDatabases: Create an Azure Cosmos database.
-
Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers: Create an Azure Cosmos container.
- Save the terraform files as main.tf, variables.tf and providers.tf to your local computer.
- Sign in to your terminal via Azure CLI or PowerShell
- Deploy via Terraform commands
- terraform init
- terraform plan
- terraform apply
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
az resource list --resource-group "your resource group name"
Get-AzResource -ResourceGroupName "your resource group name"
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources.
az group delete --name "your resource group name"
Remove-AzResourceGroup -Name "your resource group name"
In this quickstart, you created an Azure Cosmos account, a database and a container via terraform and validated the deployment. To learn more about Azure Cosmos DB and Terraform, continue on to the articles below.
- Read an Overview of Azure Cosmos DB.
- Learn more about Terraform.
- Learn more about Azure Terraform Provider.
- Manage Cosmos DB with Terraform
- Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.
- If all you know is the number of vCores and servers in your existing database cluster, read about estimating request units using vCores or vCPUs.
- If you know typical request rates for your current database workload, read about estimating request units using Azure Cosmos DB capacity planner.