Skip to content

Commit 1e725ec

Browse files
author
gicheng
committed
Updated toc, format corrections and added quickstart
1 parent 03ca637 commit 1e725ec

File tree

3 files changed

+117
-3
lines changed

3 files changed

+117
-3
lines changed

articles/cosmos-db/sql/TOC.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
- name: Create resources - JSON template
2525
displayName: ARM, Resource Manager, Template, JSON
2626
href: quick-create-template.md
27+
- name: Create resources - Terraform template
28+
displayName: ARM, Resource Manager, Template, Terraform
29+
href: quick-create-terraform.md
2730
- name: Tutorials
2831
items:
2932
- name: Create and manage data
@@ -137,6 +140,8 @@
137140
displayName: ARM
138141
- name: Bicep syntax templates
139142
href: bicep-samples.md
143+
- name: Terraform syntax templates
144+
href: terraform-samples.md
140145
- name: Azure Resource Graph queries
141146
href: ../resource-graph-samples.md
142147
- name: Concepts
@@ -1038,6 +1043,9 @@
10381043
- name: Using Resource Manager templates
10391044
href: manage-with-templates.md
10401045
displayName: ARM
1046+
- name: Using Terraform
1047+
href: manage-with-terraform.md
1048+
displayName: Terraform
10411049
- name: Move between regions
10421050
href: ../how-to-move-regions.md
10431051
- name: Prevent changes or deletion

articles/cosmos-db/sql/manage-with-terraform.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This article shows terraform samples for Core (SQL) API accounts.
2525
> * When you add or remove locations to an Azure Cosmos account, you can't simultaneously modify other properties. These operations must be done separately.
2626
> * To provision throughput at the database level and share across all containers, apply the throughput values to the database options property.
2727
28-
To create any of the Azure Cosmos DB resources below, copy the example into a new terraform file (main.tf) or alternatively, have 2 separate files for resources and variables. 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](https://github.com/Azure/terraform).
28+
To create any of the Azure Cosmos DB resources below, copy the example into a new terraform file (main.tf) or alternatively, have 2 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](https://github.com/Azure/terraform).
2929

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

@@ -75,7 +75,7 @@ Create an Azure Cosmos account in two regions with options for consistency and f
7575

7676
## Azure Cosmos DB container with server-side functionality
7777

78-
Create an Azure Cosmos account, database and container with with a stored procedure, trigger, and user-defined function.
78+
Create an Azure Cosmos account, database and container with a stored procedure, trigger, and user-defined function.
7979

8080
### main.tf
8181

@@ -89,7 +89,7 @@ Create an Azure Cosmos account, database and container with with a stored proced
8989

9090
## Azure Cosmos DB account with Azure AD and RBAC
9191

92-
Create an Azure Cosmos account, a natively maintained Role Definition, and a natively maintained Role Assignment for an AAD identity.
92+
Create an Azure Cosmos account, a natively maintained Role Definition, and a natively maintained Role Assignment for an Azure Active Directory identity.
9393

9494
### main.tf
9595

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)