Skip to content

Latest commit

 

History

History
108 lines (70 loc) · 4.84 KB

quickstart-terraform.md

File metadata and controls

108 lines (70 loc) · 4.84 KB
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

Quickstart - Create an Azure Cosmos DB database and container using Terraform

[!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.

Prerequisites

An Azure subscription or free Azure Cosmos DB trial account

Terraform should be installed on your local computer. Installation instructions can be found here.

Review the Terraform File

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.

Provider Terraform File

:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-autoscale/providers.tf":::

Main Terraform File

:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/main.tf":::

Variables Terraform File

:::code language="terraform" source="~/terraform_samples/quickstart/101-cosmos-db-manualscale/variables.tf":::

Three Cosmos DB resources are defined in the main terraform file.

Deploy via terraform

  1. Save the terraform files as main.tf, variables.tf and providers.tf to your local computer.
  2. Sign in to your terminal via Azure CLI or PowerShell
  3. Deploy via Terraform commands
    • terraform init
    • terraform plan
    • terraform apply

Validate the deployment

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"

Clean up resources

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"

Next steps

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.