Skip to content

Commit fd3dfd5

Browse files
Add Azure Cosmos DB MongoDB vCore Module (#27)
* DEVOPS-314 mongo Db cosmos cluster Azure * DEVOPS-314 make changes to out.tf to display passwd * Updating hashicorp/azurerm provider version to latest * random username passwd dependancy * removed ramdom_pet to pass username as a variable * DEVOPS-323 Mongodb changes * DEVOPS-314 fix mongo terraform module * fix mongo_password issue * Revert "fix mongo_password issue" his reverts commit a72a4cb. * password
1 parent c3129ed commit fd3dfd5

File tree

5 files changed

+227
-0
lines changed

5 files changed

+227
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "random_password" "password" {
2+
length = 32
3+
min_lower = 4
4+
min_numeric = 4
5+
min_upper = 4
6+
}

cosmosdb-mongo-vcore/mongo.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "azurerm_resource_group" "mongo_rg" {
2+
name = var.resource_group_name
3+
location = var.location
4+
tags = {
5+
Environment = upper(var.environment)
6+
Orchestrator = "Terraform"
7+
DisplayName = upper(var.resource_group_name)
8+
ApplicationName = lower(var.application_name)
9+
Temporary = upper(var.temporary)
10+
}
11+
}
12+
13+
resource "azurerm_mongo_cluster" "mongo" {
14+
name = var.mongodb_cluster_name
15+
resource_group_name = azurerm_resource_group.mongo_rg.name
16+
location = azurerm_resource_group.mongo_rg.location
17+
public_network_access = var.public_network_access
18+
19+
compute_tier = var.compute_tier
20+
shard_count = var.shard_count
21+
storage_size_in_gb = var.storage_size_in_gb
22+
high_availability_mode = var.high_availability_mode
23+
24+
administrator_username = var.admin_user
25+
administrator_password = random_password.password.result
26+
27+
create_mode = var.mongo_create_mode
28+
version = var.mongo_version
29+
30+
31+
tags = {
32+
Environment = upper(var.environment)
33+
Orchestrator = "Terraform"
34+
DisplayName = upper(var.mongodb_cluster_name)
35+
ApplicationName = lower(var.application_name)
36+
Temporary = upper(var.temporary)
37+
38+
}
39+
40+
depends_on = [random_password.password]
41+
}

cosmosdb-mongo-vcore/output.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
output "resource_group" {
2+
description = "Azure mongo DB resource group name"
3+
value = azurerm_resource_group.mongo_rg.name
4+
}
5+
6+
output "mongodb_cluster_name" {
7+
description = "Azure Mongo DB name"
8+
value = azurerm_mongo_cluster.mongo.name
9+
}
10+
11+
output "mongodb_location" {
12+
description = "Azure mongo DB location"
13+
value = azurerm_mongo_cluster.mongo.location
14+
}
15+
16+
output "public_access_enabled" {
17+
description = "Azure Mongo DB enabled public access or not"
18+
value = azurerm_mongo_cluster.mongo.public_network_access
19+
}
20+
21+
output "mongodb_admin_username" {
22+
description = "Azure Mongo DB admin username"
23+
value = azurerm_mongo_cluster.mongo.administrator_username
24+
sensitive = false
25+
}
26+
27+
output "mongodb_admin_password" {
28+
description = "Azure Mongo DB admin password"
29+
value = nonsensitive(random_password.password.result)
30+
sensitive = false
31+
}
32+
33+
output "mongodb_compute_tier" {
34+
description = "Azure Mongo DB compute tier"
35+
value = azurerm_mongo_cluster.mongo.compute_tier
36+
}
37+
38+
output "mongodb_shard_count" {
39+
description = "Azure Mongo DB shard count"
40+
value = azurerm_mongo_cluster.mongo.shard_count
41+
}
42+
43+
output "mongodb_storage_size" {
44+
description = "Azure Mongo DB storage size in GB"
45+
value = azurerm_mongo_cluster.mongo.storage_size_in_gb
46+
}

cosmosdb-mongo-vcore/providers.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = ">= 4.0"
7+
}
8+
random = {
9+
source = "hashicorp/random"
10+
version = ">= 3.1"
11+
}
12+
}
13+
}
14+
provider "azurerm" {
15+
features {}
16+
}

cosmosdb-mongo-vcore/variables.tf

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
variable "resource_group_name" {
2+
type = string
3+
description = "Azure Mongo DB Rg"
4+
default = ""
5+
}
6+
7+
variable "location" {
8+
type = string
9+
description = "Azure Mongo DB location"
10+
default = ""
11+
}
12+
13+
variable "mongodb_cluster_name" {
14+
description = "Azure Mongo DB name"
15+
type = string
16+
default = ""
17+
}
18+
19+
variable "admin_user" {
20+
description = "Azure Mongo DB admin username"
21+
type = string
22+
default = ""
23+
validation {
24+
condition = length(var.admin_user) > 0
25+
error_message = "The admin_user variable must be set to a non-empty string."
26+
}
27+
}
28+
29+
variable "environment" {
30+
default = "DEV"
31+
description = "Environment tag value in Azure"
32+
type = string
33+
validation {
34+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
35+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
36+
}
37+
}
38+
39+
variable "application_name" {
40+
default = "devwithkrishna"
41+
description = "Azure application name tag"
42+
}
43+
44+
45+
variable "temporary" {
46+
default = "TRUE"
47+
description = "Temporary tag value in Azure"
48+
type = string
49+
validation {
50+
condition = contains(["TRUE", "FALSE"], upper(var.temporary))
51+
error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'."
52+
}
53+
54+
}
55+
56+
variable "compute_tier" {
57+
description = "The compute tier to assign to the MongoDB Cluster"
58+
default = "Free"
59+
type = string
60+
validation {
61+
condition = contains(["Free", "M10", "M20", "M25", "M30", "M40", "M50", "M60", "M80", "M200"], var.compute_tier)
62+
error_message = "The compute_tier value must be one of the following: 'Free', 'M10', 'M20', 'M25', 'M30', 'M40', 'M50', 'M60', 'M80', or 'M200'."
63+
}
64+
}
65+
66+
variable "shard_count" {
67+
description = "The Number of shards to provision on the MongoDB Cluster"
68+
type = number
69+
default = 1
70+
}
71+
72+
variable "public_network_access" {
73+
default = "Enabled"
74+
description = "Public Network Access setting for the MongoDB Cluster"
75+
type = string
76+
validation {
77+
condition = contains(["Enabled", "Disabled"], var.public_network_access)
78+
error_message = "The public_network_access value must be either 'Enabled' or 'Disabled'."
79+
}
80+
}
81+
82+
variable "storage_size_in_gb" {
83+
default = 32
84+
description = "The storage size in GB for the MongoDB Cluster"
85+
type = number
86+
}
87+
88+
variable "high_availability_mode" {
89+
description = "The high availability mode for the MongoDB Cluster"
90+
default = "Disabled"
91+
type = string
92+
validation {
93+
condition = contains(["ZoneRedundantPreferred", "Disabled"], var.high_availability_mode)
94+
error_message = "The high_availability_mode value must be either 'Disabled', 'ZoneRedundantPreferred'."
95+
}
96+
}
97+
98+
variable "mongo_create_mode" {
99+
description = "The create mode for the MongoDB Cluster"
100+
default = "Default"
101+
type = string
102+
validation {
103+
condition = contains(["Default", "GeoReplica"], var.mongo_create_mode)
104+
error_message = "The mongo_create_mode value must be either 'Default' or 'GeoReplica'."
105+
}
106+
107+
}
108+
109+
variable "mongo_version" {
110+
description = "The version of the MongoDB Cluster"
111+
default = "7.0"
112+
type = string
113+
validation {
114+
condition = contains(["5.0", "6.0", "7.0"], var.mongo_version)
115+
error_message = "The mongo_version value must be either '5.0', '6.0', or '7.0'."
116+
}
117+
118+
}

0 commit comments

Comments
 (0)