|
| 1 | +--- |
| 2 | +title: Quickstart - Create an Azure Cosmos DB and a container using Terraform |
| 3 | +description: Quickstart showing how to an Azure Cosmos database and a container using Terraform |
| 4 | +author: ginsiucheng |
| 5 | +ms.author: gicheng |
| 6 | +tags: azure-resource-manager, terraform |
| 7 | +ms.service: cosmos-db |
| 8 | +ms.subservice: cosmosdb-sql |
| 9 | +ms.topic: quickstart |
| 10 | +ms.date: 09/22/2022 |
| 11 | + |
| 12 | +#Customer intent: As a database admin who is new to Azure, I want to use Azure Cosmos DB to store and manage my data. |
| 13 | +--- |
| 14 | + |
| 15 | +# Quickstart: Create an Azure Cosmos DB and a container using Terraform |
| 16 | + |
| 17 | +[!INCLUDE[appliesto-sql-api](../includes/appliesto-sql-api.md)] |
| 18 | + |
| 19 | +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](https://aka.ms/trycosmosdb). 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. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +An Azure subscription or free Azure Cosmos DB trial account |
| 24 | + |
| 25 | +- [!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)] |
| 26 | + |
| 27 | +Terraform should be installed on your local computer. Installation instructions can b |
| 28 | + |
| 29 | +## Review the Terraform File |
| 30 | + |
| 31 | +The Terraform files used in this quickstart can be found on the [terraform samples repository](https://github.com/Azure/terraform). Please create the below 3 files: providers.tf, main.tf and variables.tf. Variables can be set in command line or alternatively with a terraforms.tfvars file. |
| 32 | + |
| 33 | +### Provider Terraform File |
| 34 | + |
| 35 | +:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/providers.tf"::: |
| 36 | + |
| 37 | +### Main Terraform File |
| 38 | + |
| 39 | +:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/main.tf"::: |
| 40 | + |
| 41 | +### Variables Terraform File |
| 42 | + |
| 43 | +:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/variables.tf"::: |
| 44 | + |
| 45 | + |
| 46 | +Three Cosmos DB resources are defined in the main terraform file. |
| 47 | + |
| 48 | +- [Microsoft.DocumentDB/databaseAccounts](/azure/templates/microsoft.documentdb/databaseaccounts): Create an Azure Cosmos account. |
| 49 | + |
| 50 | +- [Microsoft.DocumentDB/databaseAccounts/sqlDatabases](/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases): Create an Azure Cosmos database. |
| 51 | + |
| 52 | +- [Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers](/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases/containers): Create an Azure Cosmos container. |
| 53 | + |
| 54 | +## Deploy via terraform |
| 55 | + |
| 56 | +1. Save the terraform files as main.tf, variables.tf and providers.tf to your local computer. |
| 57 | +2. Login to your terminal via Azure CLI or Powershell |
| 58 | +3. Deploy via Terraform commands |
| 59 | + - terraform init |
| 60 | + - terraform plan |
| 61 | + - terraform apply |
| 62 | + |
| 63 | +## Validate the deployment |
| 64 | + |
| 65 | +Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group. |
| 66 | + |
| 67 | +### [CLI](#tab/CLI) |
| 68 | + |
| 69 | +```azurecli-interactive |
| 70 | +az resource list --resource-group exampleRG |
| 71 | +``` |
| 72 | + |
| 73 | +### [PowerShell](#tab/PowerShell) |
| 74 | + |
| 75 | +```azurepowershell-interactive |
| 76 | +Get-AzResource -ResourceGroupName exampleRG |
| 77 | +``` |
| 78 | + |
| 79 | +## Clean up resources |
| 80 | + |
| 81 | +If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. |
| 82 | +When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources. |
| 83 | + |
| 84 | +# [CLI](#tab/CLI) |
| 85 | + |
| 86 | +```azurecli-interactive |
| 87 | +az group delete --name exampleRG |
| 88 | +``` |
| 89 | + |
| 90 | +# [PowerShell](#tab/PowerShell) |
| 91 | + |
| 92 | +```azurepowershell-interactive |
| 93 | +Remove-AzResourceGroup -Name exampleRG |
| 94 | +``` |
| 95 | + |
| 96 | +## Next steps |
| 97 | + |
| 98 | +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. |
| 99 | + |
| 100 | +- Read an [Overview of Azure Cosmos DB](../introduction.md). |
| 101 | +- Learn more about [Terraform](https://www.terraform.io/intro). |
| 102 | +- Learn more about [Azure Terraform Provider](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs). |
| 103 | +- [Manage Cosmos DB with Terraform](manage-with-terraform.md) |
| 104 | +- Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning. |
| 105 | + - 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](../convert-vcore-to-request-unit.md). |
| 106 | + - If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-with-capacity-planner.md). |
0 commit comments