Skip to content

Commit ba7144f

Browse files
authored
Merge pull request #269280 from gahl-levy/vcore-terraform-workaround
New doc
2 parents 880bd82 + 67f584b commit ba7144f

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

articles/cosmos-db/mongodb/vcore/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
href: quickstart-portal.md
1313
- name: Create resources - Bicep template
1414
href: quickstart-bicep.md
15+
- name: Create resources - Terraform
16+
href: quickstart-terraform.md
1517
- name: Tutorials
1618
items:
1719
- name: Build web applications
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: |
3+
Quickstart: Create a cluster with Terraform
4+
titleSuffix: Azure Cosmos DB for MongoDB vCore
5+
description: In this quickstart, create a new Azure Cosmos DB for MongoDB vCore cluster to store databases, collections, and documents by using Terraform.
6+
author: gahl-levy
7+
ms.author: gahllevy
8+
ms.service: cosmos-db
9+
ms.subservice: mongodb-vcore
10+
ms.topic: quickstart
11+
ms.date: 03/18/2024
12+
---
13+
14+
# Azure Cosmos DB for MongoDB (vCore) with Terraform
15+
This document provides instructions on using Terraform to deploy Azure Cosmos DB for MongoDB vCore resources. This involves directly calling the ARM API through Terraform.
16+
17+
## Prerequisites
18+
- Terraform installed on your machine.
19+
- An Azure subscription.
20+
21+
## Terraform Configuration
22+
Create a main.tf file and include the following configuration. Replace the resource group placeholder values (and region if needed) with your own:
23+
24+
```hcl
25+
terraform {
26+
required_providers {
27+
azurerm = { # <--- Note that it is azurerm
28+
source = "hashicorp/azurerm"
29+
version = "3.94.0"
30+
}
31+
}
32+
}
33+
provider "azurerm" {
34+
features {}
35+
}
36+
resource "azurerm_resource_group" "example" { # replace if needed
37+
name = "RESOURCE_GROUP" # replace
38+
location = "West Europe" # replace if needed
39+
}
40+
resource "azurerm_resource_group_template_deployment" "terraform-arm" {
41+
name = "terraform-arm-01"
42+
resource_group_name = azurerm_resource_group.example.name
43+
deployment_mode = "Incremental"
44+
template_content = file("template.json")
45+
}
46+
```
47+
48+
Create a template.json file and populate it with the following JSON content, making sure to replace placeholder values (CLUSTER_NAME, TEMPLATE_NAME, region, node specs, administratorLogin, administratorLoginPassword), with your specific configurations:
49+
50+
```json
51+
{
52+
"$schema": https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#,
53+
"contentVersion": "1.0.0.0",
54+
"parameters": {
55+
"CLUSTER_NAME": { // replace
56+
"defaultValue": "TEMPLATE_NAME", // replace
57+
"type": "String"
58+
}
59+
},
60+
"variables": {},
61+
"resources": [
62+
{
63+
"type": "Microsoft.DocumentDB/mongoClusters",
64+
"apiVersion": "2023-11-15-preview",
65+
"name": "[parameters('CLUSTER_NAME')]", // replace
66+
"location": "westeurope", // replace if needed
67+
"properties": {
68+
"clusterStatus": "Ready",
69+
"administratorLogin": "", // replace
70+
"administratorLoginPassword" : "", // replace
71+
"serverVersion": "6.0",
72+
"nodeGroupSpecs": [
73+
{
74+
"kind": "Shard",
75+
"sku": "M40", // replace if needed
76+
"diskSizeGB": 128,
77+
"enableHa": false, // replace if needed
78+
"nodeCount": 1
79+
}
80+
]
81+
}
82+
},
83+
{
84+
"type": "Microsoft.DocumentDB/mongoClusters/firewallRules",
85+
"apiVersion": "2023-11-15-preview",
86+
"name": "[concat(parameters('CLUSTER_NAME'), '/allowAll')]", // replace
87+
"dependsOn": [
88+
"[resourceId('Microsoft.DocumentDB/mongoClusters', parameters('CLUSTER_NAME'))]" // replace
89+
],
90+
"properties": {
91+
"startIpAddress": "0.0.0.0",
92+
"endIpAddress": "255.255.255.255"
93+
}
94+
},
95+
{
96+
"type": "Microsoft.DocumentDB/mongoClusters/firewallRules",
97+
"apiVersion": "2023-11-15-preview",
98+
"name": "[concat(parameters('CLUSTER_NAME'), '/AllowAllAzureServicesAndResourcesWithinAzureIps_2023-12-6_17-3-22')]", // replace
99+
"dependsOn": [
100+
"[resourceId('Microsoft.DocumentDB/mongoClusters', parameters('CLUSTER_NAME'))]" // replace
101+
],
102+
"properties": {
103+
"startIpAddress": "0.0.0.0",
104+
"endIpAddress": "0.0.0.0"
105+
}
106+
},
107+
{
108+
"type": "Microsoft.DocumentDB/mongoClusters/firewallRules",
109+
"apiVersion": "2023-11-15-preview",
110+
"name": "[concat(parameters('CLUSTER_NAME'), '/allowAzure')]", // replace
111+
"dependsOn": [
112+
"[resourceId('Microsoft.DocumentDB/mongoClusters', parameters('CLUSTER_NAME'))]" // replace
113+
],
114+
"properties": {
115+
"startIpAddress": "0.0.0.0",
116+
"endIpAddress": "0.0.0.0"
117+
}
118+
}
119+
]
120+
}
121+
```
122+
123+
## Deployment
124+
Execute the following commands to initialize your Terraform workspace, create an execution plan, and apply the plan to deploy your resources:
125+
126+
```bash
127+
terraform init -upgrade
128+
terraform plan -out main.tfplan
129+
terraform apply "main.tfplan"
130+
```
131+
132+
133+
## Next steps
134+
135+
> [!div class="nextstepaction"]
136+
> [Migration options for Azure Cosmos DB for MongoDB vCore](migration-options.md)

0 commit comments

Comments
 (0)