-
Notifications
You must be signed in to change notification settings - Fork 4
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
MauAraujo
wants to merge
1
commit into
dev
Choose a base branch
from
MauAraujo/add-mongodb-terraform
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
backend/infrastructure/modules/mongodbatlas_cluster/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
resource "mongodbatlas_advanced_cluster" "dashboard_cluster" { | ||
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" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/infrastructure/modules/mongodbatlas_cluster/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
backend/infrastructure/modules/mongodbatlas_project/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/infrastructure/modules/mongodbatlas_project/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.