-
Notifications
You must be signed in to change notification settings - Fork 190
doc: Adds initial structure for module examples cluster_to_advanced_cluster #3043
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
Merged
EspenAlbert
merged 7 commits into
CLOUDP-274025-dev-docs-examples
from
CLOUDP-299312_demos_cluster_mig_modules
Feb 11, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb1d505
doc: Adds initial structure for module example cluster_to_advanced_cl…
EspenAlbert aaf08c2
chore: fix lint errors
EspenAlbert 98e9ca1
refactor: directory move
EspenAlbert 0f76e6a
doc: Initial module_user
EspenAlbert d285a4a
doc: Remove hcl simplification purpose (most likely done only in modu…
EspenAlbert 08239ac
Update examples/migrate_cluster_to_advanced_cluster/module_maintainer…
EspenAlbert bfb05c0
address PR comments
EspenAlbert 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 hidden or 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,66 @@ | ||
# Module - `cluster` to `advanced_cluster` | ||
|
||
The purpose of this example is to demonstrate the upgrade path from `mongodbatlas_cluster` to `mongodbatlas_advanced_cluster` using a Terraform module. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add it's from module maintainer perspective? |
||
The example contains three module versions: | ||
|
||
Version | Purpose | Variables | Resources | ||
--- | --- | --- | --- | ||
[v1](./v1) | Baseline | 5 | `mongodbatlas_cluster` | ||
[v2](./v2) | Migrate to advanced_cluster with no change in variables or plan | 5 | `mongodbatlas_advanced_cluster` | ||
[v3](./v3) | Use the latest features of advanced_cluster | 10 | `mongodbatlas_advanced_cluster` | ||
|
||
<!-- TODO: Update the actual Variable counts --> | ||
|
||
## Dependencies | ||
<!-- TODO: Update XX versions --> | ||
<!-- TODO: Update the `versions.tf` inside each vX --> | ||
* Terraform CLI >= 1.X | ||
* Terraform MongoDB Atlas Provider v1.XX.0 | ||
* A MongoDB Atlas account | ||
* Configure the provider (can also be done with `variables.tfvars`) | ||
|
||
```bash | ||
export MONGODB_ATLAS_PUBLIC_KEY="xxxx" | ||
export MONGODB_ATLAS_PRIVATE_KEY="xxxx" | ||
``` | ||
|
||
* Configure `variables.tfvars` | ||
<!-- TODO: Example variables --> | ||
```tfvars | ||
# todo: add example variable declaration here | ||
``` | ||
|
||
## Usage | ||
|
||
### `v1` | ||
|
||
```bash | ||
# uncomment the code in main.tf marked with v1, ensure v2 and v3 is commented | ||
export | ||
terraform init | ||
terraform apply -var-file=variables.tfvars | ||
``` | ||
|
||
### `v2` | ||
|
||
```bash | ||
# uncomment the code in main.tf marked with v2, ensure v1 and v3 is commented | ||
export MONGODB_ATLAS_ADVANCED_CLUSTER_V2_SCHEMA=true # necessary for the `moved` block to work | ||
terraform init -upgrade # in case your Atlas Provider version needs to be upgraded | ||
terraform apply -var-file=variables.tfvars | ||
``` | ||
|
||
### `v3` | ||
|
||
```bash | ||
# uncomment the code in main.tf marked with v3, ensure v1 and v2 is commented | ||
export MONGODB_ATLAS_ADVANCED_CLUSTER_V2_SCHEMA=true # necessary for the `moved` block to work | ||
terraform init -upgrade # in case your Atlas Provider version needs to be upgraded | ||
terraform apply -var-file=variables.tfvars | ||
``` | ||
|
||
### Cleanup with `terraform destroy` | ||
|
||
```bash | ||
terraform destroy | ||
``` |
This file contains hidden or 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,20 @@ | ||
provider "mongodbatlas" { | ||
public_key = var.public_key | ||
private_key = var.private_key | ||
} | ||
|
||
# v1 | ||
module "cluster" { | ||
source = "./v1" | ||
|
||
auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled | ||
cluster_name = var.cluster_name | ||
cluster_type = var.cluster_type | ||
disk_size = var.disk_size | ||
instance_size = var.instance_size | ||
mongo_db_major_version = var.mongo_db_major_version | ||
project_id = var.project_id | ||
provider_name = var.provider_name | ||
replication_specs = var.replication_specs | ||
tags = var.tags | ||
} |
This file contains hidden or 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,44 @@ | ||
resource "mongodbatlas_cluster" "this" { | ||
lifecycle { | ||
precondition { | ||
condition = !(var.auto_scaling_disk_gb_enabled && var.disk_size > 0) | ||
error_message = "Must use either auto_scaling_disk_gb_enabled or disk_size, not both." | ||
} | ||
} | ||
|
||
project_id = var.project_id | ||
name = var.cluster_name | ||
|
||
auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled | ||
cluster_type = var.cluster_type | ||
disk_size_gb = var.disk_size | ||
mongo_db_major_version = var.mongo_db_major_version | ||
provider_instance_size_name = var.instance_size | ||
provider_name = var.provider_name | ||
|
||
dynamic "tags" { | ||
for_each = var.tags | ||
content { | ||
key = tags.key | ||
value = tags.value | ||
} | ||
} | ||
|
||
dynamic "replication_specs" { | ||
for_each = var.replication_specs | ||
content { | ||
num_shards = replication_specs.value.num_shards | ||
zone_name = replication_specs.value.zone_name | ||
|
||
dynamic "regions_config" { | ||
for_each = replication_specs.value.regions_config | ||
content { | ||
electable_nodes = regions_config.value.electable_nodes | ||
priority = regions_config.value.priority | ||
read_only_nodes = regions_config.value.read_only_nodes | ||
region_name = regions_config.value.region_name | ||
} | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
examples/modules/cluster_to_advanced_cluster/v1/outputs.tf
This file contains hidden or 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 @@ | ||
output "mongodb_raw_connection_strings" { | ||
value = mongodbatlas_cluster.this.connection_strings | ||
description = "This is the raw list of MongoDB Atlas connection strings. Note, these do not show the connection mechanism of the database details" | ||
} | ||
|
||
output "cluster_name" { | ||
value = mongodbatlas_cluster.this.name | ||
description = "MongoDB Atlas cluster name" | ||
} | ||
|
||
output "project_id" { | ||
value = mongodbatlas_cluster.this.project_id | ||
description = "MongoDB Atlas project id" | ||
} | ||
|
||
output "replication_specs" { | ||
value = mongodbatlas_cluster.this.replication_specs | ||
description = "Replication Specs for cluster" | ||
} | ||
|
||
output "mongodbatlas_cluster" { | ||
value = mongodbatlas_cluster.this | ||
description = "Full cluster configuration for mongodbatlas_cluster resource" | ||
} |
68 changes: 68 additions & 0 deletions
68
examples/modules/cluster_to_advanced_cluster/v1/variables.tf
This file contains hidden or 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,68 @@ | ||
variable "project_id" { | ||
type = string | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
} | ||
|
||
variable "cluster_type" { | ||
type = string | ||
|
||
validation { | ||
condition = contains(["REPLICASET", "SHARDED", "GEOSHARDED"], var.cluster_type) | ||
error_message = "Valid supported cluster types are \"REPLICASET\", \"SHARDED\" or \"GEOSHARDED\"." | ||
} | ||
} | ||
|
||
variable "instance_size" { | ||
type = string | ||
} | ||
|
||
variable "mongo_db_major_version" { | ||
type = string | ||
} | ||
|
||
variable "provider_name" { | ||
type = string | ||
} | ||
|
||
# OPTIONAL VARIABLES | ||
|
||
variable "disk_size" { | ||
type = number | ||
default = 0 | ||
} | ||
|
||
variable "auto_scaling_disk_gb_enabled" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "replication_specs" { | ||
type = list(object({ | ||
num_shards = number | ||
zone_name = string | ||
regions_config = set(object({ | ||
region_name = string | ||
electable_nodes = number | ||
priority = number | ||
read_only_nodes = number | ||
})) | ||
})) | ||
default = [{ | ||
num_shards = 1 | ||
zone_name = "Zone 1" | ||
regions_config = [{ | ||
region_name = "US_EAST_1" | ||
electable_nodes = 3 | ||
priority = 7 | ||
read_only_nodes = 0 | ||
}] | ||
}] | ||
} |
This file contains hidden or 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,9 @@ | ||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
version = "~> 1.22" | ||
} | ||
} | ||
required_version = ">= 1.0" | ||
} |
Empty file.
This file contains hidden or 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,3 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
} |
Empty file.
This file contains hidden or 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,3 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
} |
This file contains hidden or 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,82 @@ | ||
variable "public_key" { | ||
description = "Public API key to authenticate to Atlas" | ||
type = string | ||
default = "" | ||
} | ||
variable "private_key" { | ||
description = "Private API key to authenticate to Atlas" | ||
type = string | ||
default = "" | ||
} | ||
|
||
# v1 & v2 variables | ||
variable "project_id" { | ||
type = string | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
} | ||
|
||
variable "cluster_type" { | ||
type = string | ||
|
||
validation { | ||
condition = contains(["REPLICASET", "SHARDED", "GEOSHARDED"], var.cluster_type) | ||
error_message = "Valid supported cluster types are \"REPLICASET\", \"SHARDED\" or \"GEOSHARDED\"." | ||
} | ||
} | ||
|
||
variable "instance_size" { | ||
type = string | ||
} | ||
|
||
variable "mongo_db_major_version" { | ||
type = string | ||
} | ||
|
||
variable "provider_name" { | ||
type = string | ||
} | ||
|
||
# OPTIONAL VARIABLES | ||
|
||
variable "disk_size" { | ||
type = number | ||
default = 0 | ||
} | ||
|
||
variable "auto_scaling_disk_gb_enabled" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "replication_specs" { | ||
type = list(object({ | ||
num_shards = number | ||
zone_name = string | ||
regions_config = set(object({ | ||
region_name = string | ||
electable_nodes = number | ||
priority = number | ||
read_only_nodes = number | ||
})) | ||
})) | ||
default = [{ | ||
num_shards = 1 | ||
zone_name = "Zone 1" | ||
regions_config = [{ | ||
region_name = "US_EAST_1" | ||
electable_nodes = 3 | ||
priority = 7 | ||
read_only_nodes = 0 | ||
}] | ||
}] | ||
} | ||
|
||
# v3 extra variables (TODO) |
This file contains hidden or 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,9 @@ | ||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
version = "~> 1.22" | ||
} | ||
} | ||
required_version = ">= 1.0" | ||
} |
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.
Notice directory location
examples/modules/{module_name}
👍 or 👎 ?
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.
as we'll have 3 examples of clu2adv and one doesn't have modules, what about something like:
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.
I like your suggestion 👍
Changed ✅