Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formalize MongoDB deployment #7514

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/infrastructure/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module "s3" {
env = var.env
}

# Dashboard database provider. Credentials are filled in by CI and
# passed as environment variables to terraform.
provider "mongodbatlas" {}


# Region-specific modules, these are enabled only on certain regions

# Enable all AWS regions on Terraform. Doing this will create
Expand Down
52 changes: 52 additions & 0 deletions backend/infrastructure/modules/mongodbatlas_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "mongodbatlas_advanced_cluster" "dashboard_cluster" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this run in our AWS or its in MongoDB? Could I get access to it?

Copy link
Author

@MauAraujo MauAraujo Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it runs on MongoDB Atlas, but you can select which cloud provider(s) to use. I created an account for the demo, but when we formalize the deploy we should have an organization account. You can monitor the cluster from that page.

project_id = var.project_id
name = var.cluster_name
cluster_type = "REPLICASET"
mongodb_major_version = var.mongodbversion
replication_specs {
electable_specs {
instance_size = "M0"
node_count = 3
}
analytics_specs {
instance_size = "M0"
node_count = 1
}
provider_name = var.cloud_provider
priority = 1
region_name = var.region
}
}

resource "mongodbatlas_project_ip_access_list" "ip" {
project_id = var.project.id

# Note: Since the Netlify site changes ip address constantly,
# we allow access for all ip addresses. Other methods should
# be used to authorize access to the cluster.
ip_address = "0.0.0.0/0"
comment = "Allow access to all ip addresses."
}

resource "mongodbatlas_database_user" "dashboard_user" {
# TODO: Credentials should be filled in by CI.
username = ""
password = ""
project_id = var.project_id
auth_database_name = "admin"

roles {
role_name = "readWrite"
database_name = var.database_name # The database name and collection name need not exist in the cluster before creating the user.
}

scopes {
name = var.cluster_name
type = "CLUSTER"
}

labels {
key = "Name"
value = "Dashboard User"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
variable "org_id" {
type = string
description = "MongoDB Organization ID"
}
variable "project_id" {
type = string
description = "The MongoDB Atlas Project ID"
}
variable "cluster_name" {
type = string
description = "The MongoDB Atlas Cluster Name"
}
variable "cloud_provider" {
type = string
description = "The cloud provider to use, must be AWS, GCP or AZURE"
}
variable "region" {
type = string
description = "MongoDB Atlas Cluster Region, must be a region for the provider given"
}
variable "mongodbversion" {
type = string
description = "The Major MongoDB Version"
}
16 changes: 16 additions & 0 deletions backend/infrastructure/modules/mongodbatlas_project/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "mongodbatlas_project" "dashboard" {
name = var.project_name
org_id = var.org_id

# TODO: not sure if these options are enabled by default or
# are addons that incur in costs.
is_collect_database_specifics_statistics_enabled = true
is_data_explorer_enabled = true
is_performance_advisor_enabled = true
is_realtime_performance_panel_enabled = true
is_schema_advisor_enabled = true
}

output "project_id" {
value = mongodbatlas_project.dashboard.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "org_id" {
type = string
description = "MongoDB Organization ID"
}
variable "project_name" {
type = string
description = "The MongoDB Atlas Project Name"
}