Skip to content

Commit 661da59

Browse files
authored
doc: Adds basic module for mongodbatlas_advanced_cluster (Preview for MongoDB Atlas Provider 2.0.0) (#3270)
* doc: Adds example of v4 module of new advanced_cluster * refactor: move v4 to basic_module * chore: update external issue links * feat: add call to basic module for mongodbatlas_advanced_cluster * doc: update README.md with description and add example.tfvars * refactor: move files back to v4 * doc: Add description for the module_maintainer and remove old variables. * chore: remove unused link * apply suggestions
1 parent e79a836 commit 661da59

File tree

12 files changed

+305
-6
lines changed

12 files changed

+305
-6
lines changed

docs/guides/cluster-to-advanced-cluster-migration-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The basic experience when using the `moved` block is as follows:
5656
3. Comment out or delete the `mongodbatlas_cluster` resource definition.
5757
4. Update the references from your previous cluster resource: `mongodbatlas_cluster.this.XXXX` to the new `mongodbatlas_advanced_cluster.this.XXX`.
5858
- Double check [output-changes](#output-changes) to ensure the underlying configuration stays unchanged.
59-
- If you are using output variables that use the new resource `mongodbatlas_advanced_cluster.this`, the plan output can be more verbose than expected (extra `Note: Objects have changed outside of Terraform` section). Consider adding/updating output variables only **after** performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1109)).
59+
- If you are using output variables that use the new resource `mongodbatlas_advanced_cluster.this`, the plan output can be more verbose than expected (extra `Note: Objects have changed outside of Terraform` section). Consider adding/updating output variables only **after** performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform/issues/36796).
6060
5. Add the `moved` block to your configuration file, e.g.:
6161
```terraform
6262
moved {

examples/migrate_cluster_to_advanced_cluster/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The [CLI Plugin](https://github.com/mongodb-labs/atlas-cli-plugin-terraform) hel
4949
## Manual updates to the Terraform configuration
5050

5151
1. Ensure all references are updated (see example of updates in [outputs.tf](outputs.tf))
52-
1. Ensure you are not adding any output variables that use the new `mongodbatlas_advanced_cluster` resource. Referencing the new resource before moving can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1109)).
52+
1. Ensure you are not adding any output variables that use the new `mongodbatlas_advanced_cluster` resource. Referencing the new resource before moving can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform/issues/36796).
5353
2. Comment out the `mongodbatlas_cluster` in `{CLUSTER_IN}.tf`
5454
3. Add the moved block for each resource migrated in `{CLUSTER_OUT}.tf`
5555
```terraform

examples/migrate_cluster_to_advanced_cluster/module_maintainer/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Step | Purpose | Resources
99
[Step 1](./v1) | Baseline | `mongodbatlas_cluster`
1010
[Step 2](./v2) | Migrate to advanced_cluster with no change in variables or plan | `mongodbatlas_advanced_cluster`
1111
[Step 3](./v3) | Use the latest features of advanced_cluster | `mongodbatlas_advanced_cluster`
12+
[Step 4](./v4) | Future proofs the module by removing all `mongodbatlas_cluster` references | `mongodbatlas_advanced_cluster`
1213

1314
The rest of this document summarizes the different implementations:
1415

@@ -83,15 +84,15 @@ moved {
8384
- Adds `data "mongodbatlas_cluster" "this"` to avoid breaking changes in `outputs.tf` (see below).
8485

8586
### [`outputs.tf`](v2/outputs.tf)
86-
- Ensure you are not adding any output variables that use the new `mongodbatlas_advanced_cluster` resource. Referencing the new resource before moving can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1109)).
87+
- Ensure you are not adding any output variables that use the new `mongodbatlas_advanced_cluster` resource. Referencing the new resource before moving can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform/issues/36796).
8788
- Ensure compatibility with `v1` outputs by modifying:
8889
- `replication_specs`, uses `data.mongodbatlas_cluster.this.replication_specs` to keep the same format.
8990
- `mongodbatlas_cluster`, uses the `data.mongodbatlas_cluster.this` to keep the same format.
9091

9192

9293
## Step 3: Module `v3` Implementation Changes and Highlights
9394
This module adds variables to support the latest `mongodbatlas_advanced_cluster` features while staying compatible with the old input variables.
94-
The module supports standalone usage when there is no existing `mongodbatlas_cluster` and also upgrading from `v1` using a `moved` block. However, upgrading directly from `v1` can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1109)).
95+
The module supports standalone usage when there is no existing `mongodbatlas_cluster` and also upgrading from `v1` using a `moved` block. However, upgrading directly from `v1` can lead to a more verbose plan output (extra `Note: Objects have changed outside of Terraform` section) when performing the move (see more in the [Github Issue](https://github.com/hashicorp/terraform/issues/36796).
9596
The module also supports changing an existing `mongodbatlas_advanced_cluster` created in `v2`.
9697

9798
### [`variables.tf`](v3/variables.tf)
@@ -144,3 +145,25 @@ output "mongodbatlas_cluster" {
144145
description = "Full cluster configuration for mongodbatlas_cluster resource, will be null if var.replication_specs_new is set"
145146
}
146147
```
148+
149+
## Step 4: Module `v4` Implementation Changes and Highlights
150+
This module marks the end of the migration to `mongodbatlas_advanced_cluster`.
151+
We future-proof the module by removing references to the `mongodbatlas_cluster` data source and only allowing the latest schema for the `replication_specs` variable.
152+
A major version bump would typically accompany this module version since we remove and rename input and output variables.
153+
The reduced compatibility simplifies the module but forces the module user to rename their input variable `replication_specs_new` to `replication_specs`.
154+
You can keep the `replication_specs_new` variable name, but it might confuse new module users and complicate future updates.
155+
156+
### [`variables.tf`](v4/variables.tf)
157+
- Remove the `replication_specs`, `auto_scaling_disk_gb_enabled`, `disk_size`, `provider_name`, and `instance_size`.
158+
- Rename the `replication_specs_new` to `replication_specs`.
159+
- Remove the default (`[]`) of `replication_specs`.
160+
161+
### [`main.tf`](v4/main.tf)
162+
- Remove `locals` block (no longer needed to modify the old replication_spec variable to fit the new `mongodbatlas_advanced_cluster` schema).
163+
- Remove the `moved` block.
164+
- Remove the `mongodbatlas_cluster` data source.
165+
166+
### [`outputs.tf`](v4/outputs.tf)
167+
- Remove conditional logic from `replication_specs`.
168+
- Flatten `mongodb_connection_strings` to use `mongodbatlas_advanced_cluster.this.connection_strings` directly instead of wrapping inside a list.
169+
- Remove the `mongodbatlas_cluster`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "mongodbatlas_advanced_cluster" "this" {
2+
project_id = var.project_id
3+
name = var.cluster_name
4+
cluster_type = var.cluster_type
5+
mongo_db_major_version = var.mongo_db_major_version
6+
replication_specs = var.replication_specs
7+
tags = var.tags
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
output "mongodb_connection_strings" {
2+
value = mongodbatlas_advanced_cluster.this.connection_strings
3+
description = "Map of Uniform Resource Locators that point to the MongoDB database."
4+
}
5+
6+
output "cluster_name" {
7+
value = mongodbatlas_advanced_cluster.this.name
8+
description = "MongoDB Atlas cluster name"
9+
}
10+
11+
output "project_id" {
12+
value = mongodbatlas_advanced_cluster.this.project_id
13+
description = "MongoDB Atlas project id"
14+
}
15+
16+
output "replication_specs" {
17+
value = mongodbatlas_advanced_cluster.this.replication_specs
18+
description = "Replication Specs for the cluster"
19+
}
20+
21+
output "mongodbatlas_advanced_cluster" {
22+
value = resource.mongodbatlas_advanced_cluster.this
23+
description = "Full cluster configuration for mongodbatlas_advanced_cluster resource"
24+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
variable "project_id" {
2+
description = "Unique 24-hexadecimal digit string that identifies your project. Use the `/groups` at https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Projects/operation/listProjects endpoint to retrieve all projects to which the authenticated user has access. **NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups"
3+
type = string
4+
}
5+
6+
variable "cluster_name" {
7+
description = "Human-readable label that identifies this cluster."
8+
type = string
9+
}
10+
11+
variable "cluster_type" {
12+
description = "Configuration of nodes that comprise the cluster."
13+
type = string
14+
}
15+
16+
17+
variable "mongo_db_major_version" {
18+
description = "MongoDB major version of the cluster. On creation: Choose from the available versions of MongoDB, or leave unspecified for the current recommended default in the MongoDB Cloud platform. The recommended version is a recent Long Term Support version. The default is not guaranteed to be the most recently released version throughout the entire release cycle. For versions available in a specific project, see the linked documentation or use the API endpoint for https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Projects/operation/getProjectLtsVersions. On update: Increase version only by 1 major version at a time. If the cluster is pinned to a MongoDB feature compatibility version exactly one major version below the current MongoDB version, the MongoDB version can be downgraded to the previous major version."
19+
type = string
20+
}
21+
22+
variable "tags" {
23+
description = "Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster."
24+
type = map(string)
25+
default = {}
26+
}
27+
28+
variable "replication_specs" {
29+
description = "List of replication specifications using new mongodbatlas_advanced_cluster format"
30+
type = list(object({
31+
zone_name = optional(string, "Zone 1")
32+
33+
region_configs = list(object({
34+
region_name = string
35+
provider_name = string
36+
priority = optional(number, 7)
37+
38+
auto_scaling = optional(object({
39+
disk_gb_enabled = optional(bool, false)
40+
}), null)
41+
42+
read_only_specs = optional(object({
43+
node_count = number
44+
instance_size = string
45+
disk_size_gb = optional(number, null)
46+
ebs_volume_type = optional(string, null)
47+
disk_iops = optional(number, null)
48+
}), null)
49+
analytics_specs = optional(object({
50+
node_count = number
51+
instance_size = string
52+
disk_size_gb = optional(number, null)
53+
ebs_volume_type = optional(string, null)
54+
disk_iops = optional(number, null)
55+
}), null)
56+
electable_specs = object({
57+
node_count = number
58+
instance_size = string
59+
disk_size_gb = optional(number, null)
60+
ebs_volume_type = optional(string, null)
61+
disk_iops = optional(number, null)
62+
})
63+
}))
64+
}))
65+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
version = "~> 1.29"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}

examples/migrate_cluster_to_advanced_cluster/module_user/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Migration Step Code | `mongodbatlas` version | Config Changes | Plan Changes
99
[Step 1](./v1) | `<= 1.29.0` | Baseline configuration | -
1010
[Step 2](./v2) | `>= 1.29.0` | Only change to `v2` module version | No changes. Only moved.
1111
[Step 3](./v3) | `>= 1.29.0` | Usage of new variables to support multi-cloud and independent shard scaling | Yes (new features)
12+
[Step 4](./v4) | `>= 1.29.0` | Rename `replication_specs_new` to `replication_specs` | No
1213

1314

1415
The rest of this example is a step by step guide on how to migrate from `mongodbatlas_cluster` to `mongodbatlas_advanced_cluster`:
@@ -26,8 +27,8 @@ The rest of this example is a step by step guide on how to migrate from `mongodb
2627
- [Cleanup with `terraform destroy`](#cleanup-with-terraform-destroy)
2728

2829
## Dependencies
29-
- Terraform CLI >= 1.8-
30-
- Terraform MongoDB Atlas Provider `>=v1.29.0`-
30+
- Terraform CLI >= 1.8
31+
- Terraform MongoDB Atlas Provider `>=v1.29.0`
3132
- A MongoDB Atlas account.
3233
- Configure the provider (can also be done by configuring `public_key` and `private_key` in a `provider.tfvars`).
3334

@@ -102,6 +103,22 @@ terraform init -upgrade # in case your Atlas Provider version needs to be upgrad
102103
terraform apply -var-file=../v3.tfvars # updated variables to enable latest mongodb_advanced_cluster features
103104
```
104105

106+
## Step 4: Adapt to the future proof `v4` module without any `mongodbatlas_cluster` references
107+
108+
### Update `v4.tfvars`
109+
110+
See the example in [v4.tfvars](v4.tfvars).
111+
This example renames the variable `replication_specs_new` to `replication_specs`.
112+
113+
### Run `terraform plan` to ensure no plan changes
114+
```bash
115+
cd v4
116+
cp ../v3/terraform.tfstate . # if you are not using a remote state
117+
export MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true # necessary to use the latest schema
118+
terraform init -upgrade # in case your Atlas Provider version needs to be upgraded
119+
terraform plan -var-file=../v4.tfvars
120+
```
121+
105122
## Cleanup with `terraform destroy`
106123

107124
```bash
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
project_id = "664619d870c247237f4b86a6"
2+
cluster_name = "module-cluster"
3+
cluster_type = "SHARDED"
4+
mongo_db_major_version = "8.0"
5+
6+
tags = {
7+
env = "examples"
8+
module = "basic_module"
9+
}
10+
11+
replication_specs = [
12+
{ # shard 1
13+
region_configs = [{
14+
electable_specs = {
15+
disk_size_gb = 50 # must be the same for all replication specs
16+
instance_size = "M30"
17+
node_count = 3
18+
}
19+
priority = 7
20+
provider_name = "AWS"
21+
read_only_specs = {
22+
disk_size_gb = 50
23+
instance_size = "M30"
24+
node_count = 1
25+
}
26+
region_name = "US_EAST_1"
27+
}]
28+
zone_name = "Zone 1"
29+
},
30+
{ # shard 2
31+
region_configs = [{
32+
electable_specs = {
33+
disk_size_gb = 50
34+
instance_size = "M50"
35+
node_count = 3
36+
}
37+
priority = 7
38+
provider_name = "AWS"
39+
read_only_specs = {
40+
disk_size_gb = 50
41+
instance_size = "M50"
42+
node_count = 1
43+
}
44+
region_name = "US_EAST_1"
45+
}]
46+
zone_name = "Zone 1"
47+
},
48+
]
49+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
5+
6+
module "cluster" {
7+
source = "../../module_maintainer/v4"
8+
9+
cluster_name = var.cluster_name
10+
cluster_type = var.cluster_type
11+
mongo_db_major_version = var.mongo_db_major_version
12+
project_id = var.project_id
13+
replication_specs = var.replication_specs
14+
tags = var.tags
15+
}
16+
17+
output "mongodb_connection_strings" {
18+
description = "Collection of Uniform Resource Locators that point to the MongoDB database."
19+
value = module.cluster.mongodb_connection_strings
20+
}

0 commit comments

Comments
 (0)