
This module creates and manages a MongoDB cluster in DigitalOcean, providing capabilities for managing databases and users
private_uri
attribute of MongoDB cluster on every request, Terraform detects this as a change in resource state.Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:
shellterraform login solutions.corewide.com
Initialize mandatory providers:
Copy and paste into your Terraform configuration and insert the variables:
hclmodule "tf_do_mongodb" {
source = "solutions.corewide.com/digitalocean/tf-do-mongodb/digitalocean"
version = "~> 1.3.0"
# specify module inputs here or try one of the examples below
...
}
Initialize the setup:
shellterraform init
Corewide DevOps team strictly follows Semantic Versioning
Specification
to
provide our clients with products that have predictable upgrades between versions. We
recommend
pinning
patch versions of our modules using pessimistic
constraint operator (~>
) to prevent breaking changes during upgrades.
To get new features during the upgrades (without breaking compatibility), use
~> 1.3
and run
terraform init -upgrade
For the safest setup, use strict pinning with version = "1.3.0"
All notable changes to this project are documented here.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
trusted_sources
variablestorage_size_mib
because MongoDB disk size inherits that of its machine type.engine_version
and maintenance_window.hour
to prevent conflict between Terraform and DigitalOcean valuesv5.0
First stable version
Full MongoDB setup creates 2-node MongoDB cluster (with one standby node) on specified VPC with db-s-2vcpu-2gb
machine type, 20 GB storage size, myuser_db
database, myuser
user, adds trusted sources, and tags the cluster as dev
:
hclmodule "db" {
source = "solutions.corewide.com/digitalocean/tf-do-mongodb/digitalocean"
version = "~> 1.3"
region = "fra1"
name_prefix = "develop"
vpc_id = "xxxxxxxx-yyyy-zzzz-xxxx-yyyyyyyyyyyy"
engine_version = "7"
node_count = 2
machine_size = "db-s-2vcpu-2gb"
maintenance_window = {
day = "Tue"
hour = 15
}
databases = [
"myuser_db",
]
users = [
"myuser",
]
trusted_sources = [
{
type = "ip_addr"
value = "10.114.32.24"
},
{
type = "k8s"
value = "123ab45-67c8-de9f0-1ghj23"
},
]
tags = [
"dev",
]
}
Minimal MongoDB setup creates 1-node MongoDB cluster with db-s-1vcpu-1gb
machine type (by default, admin
database, privileged doadmin
and do-readonly
users are created):
hclmodule "db" {
source = "solutions.corewide.com/digitalocean/tf-do-mongodb/digitalocean"
version = "~> 1.3"
region = "fra1"
name_prefix = "develop"
}
Variable | Description | Type | Default | Required | Sensitive |
---|---|---|---|---|---|
name_prefix |
Name prefix for the created resources | string |
yes | no | |
region |
DigitalOcean region to create resources in | string |
yes | no | |
databases |
List of additional databases to create inside MongoDB cluster | list(string) |
[] |
no | no |
engine_version |
MongoDB engine version | string |
7 |
no | no |
machine_size |
Database Droplet size associated with MongoDB cluster | string |
db-s-1vcpu-1gb |
no | no |
machine_storage_size |
Custom machine storage size (Gb). Reserved for future use. As of Nov 2024, MongoDB disk size inherits that of its machine type. | number |
10 |
no | no |
maintenance_window |
Maintenance window configuration | object |
{} |
no | no |
maintenance_window.day |
The day of the week (Mon , Tue , etc.) the maintenance window occurs |
string |
Mon |
no | no |
maintenance_window.hour |
The hour when the maintenance updates are applied, in UTC 24-hour format. Examples: 2 , 3 , 23 |
number |
2 |
no | no |
node_count |
Number of MongoDB master nodes | number |
1 |
no | no |
tags |
List of tags to be assigned to the cluster resource | list(string) |
[] |
no | no |
trusted_sources |
List of trusted sources to restrict connections to the database cluster | list(object) |
[] |
no | no |
trusted_sources[*].type |
Type of resource that the firewall rule allows to access the database cluster. Possible values are: droplet , k8s , ip_addr , tag , or app |
string |
yes | no | |
trusted_sources[*].value |
ID of the specific resource, name of a tag applied to a group of resources, or IP address that the firewall rule allows to access the database cluster | string |
yes | no | |
users |
List of usernames to create | list(string) |
[] |
no | no |
vpc_id |
The ID of the VPC where the database cluster will be located. If not provided, default DigitalOcean VPC is used | string |
no | no |
Output | Description | Type | Sensitive |
---|---|---|---|
connection_parameters |
Connection parameters for MongoDB | map |
yes |
database_cluster |
Cluster resource attributes | resource |
yes |
databases |
Database resources' attributes | computed |
no |
users |
User resources' attributes | computed |
yes |
Dependency | Version | Kind |
---|---|---|
terraform |
>= 1.3 |
CLI |
digitalocean/digitalocean |
~> 2.34 |
provider |