Skip to content

Commit b7477a2

Browse files
lantolicorryroot
andauthored
doc: Improve documentation for effective fields example (#3954)
Co-authored-by: corryroot <[email protected]>
1 parent ecd5991 commit b7477a2

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

examples/mongodbatlas_advanced_cluster/effective_fields/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ effective_fields/
1515

1616
- **Migrating an existing module?** Review both [module_existing](./module_existing/) and [module_effective_fields](./module_effective_fields/) to understand the changes.
1717
- **Creating a new module?** Go directly to [module_effective_fields](./module_effective_fields/).
18-
- **How to use these modules?** See [module_user](./module_user/) - shows that migration only requires changing the module source.
18+
- **How to use these modules?** See [module_user](./module_user/). It shows that migration requires only that you change the module source.
1919

2020
## What is use_effective_fields?
2121

2222
When auto-scaling is enabled, Atlas automatically adjusts instance sizes and disk capacity. This creates [configuration drift](https://developer.hashicorp.com/terraform/tutorials/state/resource-drift) that requires management.
2323

24-
**Future direction:** In provider v3.x, `use_effective_fields = true` will become the default behavior and the flag will be removed. Migrating now is recommended to prepare for this transition.
24+
`use_effective_fields` is an attribute for the `mongodbatlas_advanced_cluster` resource and data sources that solves this problem. When enabled on the resource, it eliminates the need for `lifecycle.ignore_changes` blocks by treating Atlas-managed values as part of the expected state rather than drift.
25+
26+
Additionally, the data sources provide `effective_*_specs` attributes (`effective_electable_specs`, `effective_analytics_specs`, `effective_read_only_specs`) that expose the actual provisioned values from Atlas, providing visibility into what Atlas has scaled to versus what was configured.
27+
28+
For more details, see [Auto-Scaling with Effective Fields](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster#auto-scaling-with-effective-fields) documentation.
2529

2630
### module_existing approach
2731

32+
**This was the only available approach before `use_effective_fields` was introduced and is no longer recommended.** This section is included only for understanding migration from existing implementations. For new modules or when migrating, use the [module_effective_fields approach](#module_effective_fields-approach) (see [Migration Guide](#migration-guide) below).
33+
2834
Uses `mongodbatlas_advanced_cluster` resource with `lifecycle.ignore_changes` block listing all auto-scalable fields (instance_size, disk_size_gb, disk_iops) for all node types across regions and replication specs. When auto-scaling is enabled, Atlas may adjust all three fields regardless of which auto-scaling type is enabled (for optimal performance). Includes `mongodbatlas_advanced_cluster` data source to query actual provisioned values from Atlas API, as ignored fields are from the Terraform state.
2935

3036
**Known issues with this approach:**
@@ -58,16 +64,16 @@ See [module_effective_fields/main.tf](./module_effective_fields/main.tf) for imp
5864
3. **Update outputs:** Reference data source for replication specs.
5965
4. **Result:** Eliminates lifecycle blocks, prevents drift, maintains output compatibility.
6066

61-
**Phase 2: Enhanced visibility (prepares for provider v3.x)**
67+
**Phase 2: Enhanced visibility (prepares for future provider major versions)**
6268

63-
This breaking change prepares for provider v3.x where effective fields will be the default behavior:
69+
Prepares for future provider major versions where effective fields will be the default behavior. This involves changes to data source outputs:
6470

6571
1. **Update data source:** Add `use_effective_fields = true` to data source.
6672
2. **Update outputs:** Expose both configured specs and effective specs separately, or document that clients must use `effective_*_specs` for actual values.
67-
3. **Update documentation:** Clearly communicate the breaking change - data source now returns both client-provided specs (via `*_specs`) and actual provisioned specs (via `effective_*_specs`). Clients must switch from using normal specs (which previously returned actual values) to using `effective_*_specs` to get actual values.
68-
4. **Result:** Clear separation between configured intent and actual provisioned values, aligned with future v3.x behavior.
73+
3. **Update documentation:** Clearly document that data source now returns both client-provided specs (via `*_specs`) and actual provisioned specs (via `effective_*_specs`). Clients must switch from using normal specs (which previously returned actual values) to using `effective_*_specs` to get actual values.
74+
4. **Result:** Clear separation between configured intent and actual provisioned values, aligned with future provider major version behavior.
6975

70-
**Breaking change impact:** Module users accessing `*_specs` for actual provisioned values must switch to using `effective_*_specs` attributes (effective_electable_specs, effective_analytics_specs, effective_read_only_specs).
76+
**Migration impact:** Module users accessing `*_specs` for actual provisioned values must switch to using `effective_*_specs` attributes (effective_electable_specs, effective_analytics_specs, effective_read_only_specs).
7177

7278
See detailed implementation in [module_existing](./module_existing/) and [module_effective_fields](./module_effective_fields/).
7379

examples/mongodbatlas_advanced_cluster/effective_fields/module_effective_fields/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ resource "mongodbatlas_advanced_cluster" "this" {
2020
- *_specs (electable_specs, analytics_specs, read_only_specs) return actual provisioned values
2121
- Recommended for migrating from lifecycle.ignore_changes while maintaining compatibility with module_existing behavior
2222
23-
Phase 2 (breaking change, prepares for v3.x):
23+
Phase 2 (prepares for future provider major versions):
2424
- Set use_effective_fields = true on the data source
2525
- *_specs return configured values, effective_*_specs return actual provisioned values
2626
- Module users must switch from *_specs to effective_*_specs for actual values
27-
- Recommended for new modules or when preparing for provider v3.x
27+
- Recommended for new modules or when preparing for future provider major versions
2828
*/
2929
data "mongodbatlas_advanced_cluster" "this" {
3030
project_id = mongodbatlas_advanced_cluster.this.project_id

examples/mongodbatlas_advanced_cluster/effective_fields/module_effective_fields/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ output "connection_strings" {
3434
- *_specs return actual provisioned values for backward compatibility with module_existing
3535
- Data source also exposes effective_*_specs attributes
3636
37-
For Phase 2 approach (breaking change for v3.x preparation), see main.tf data source comments.
37+
For Phase 2 approach (prepares for future provider major versions), see main.tf data source comments.
3838
*/
3939
output "replication_specs" {
4040
description = "Cluster replication specifications (actual values for backward compatibility)"

examples/mongodbatlas_advanced_cluster/effective_fields/module_existing/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ resource "mongodbatlas_project" "this" {
55
}
66

77
/*
8-
Create Atlas Advanced Cluster with auto-scaling.
9-
This approach uses lifecycle.ignore_changes blocks to prevent Terraform
10-
from detecting drift when Atlas auto-scales the cluster.
8+
This module simulates an existing implementation using lifecycle.ignore_changes blocks.
9+
10+
This was the only available approach before use_effective_fields was introduced and is no longer
11+
recommended. This implementation is included only for understanding migration from existing modules.
12+
For new modules, use the module_effective_fields approach instead.
1113
*/
1214
resource "mongodbatlas_advanced_cluster" "this" {
1315
project_id = mongodbatlas_project.this.id
@@ -17,9 +19,6 @@ resource "mongodbatlas_advanced_cluster" "this" {
1719
tags = var.tags
1820

1921
/*
20-
lifecycle.ignore_changes is required when auto-scaling is enabled
21-
to prevent Terraform from trying to revert Atlas-managed changes.
22-
2322
When auto-scaling is enabled (either compute or disk auto-scaling), Atlas may adjust
2423
instance_size, disk_size_gb, and disk_iops regardless of which auto-scaling type is enabled.
2524
Therefore, all three attributes must be ignored to prevent unintended changes.

examples/mongodbatlas_advanced_cluster/effective_fields/module_user/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ To see the old approach with `lifecycle.ignore_changes`, edit the module source
4444
- `effective_*_specs` attributes also available with actual values.
4545
- Seamless migration with no output changes.
4646

47-
**module_effective_fields (Phase 2 - breaking change, prepares for v3.x):**
47+
**module_effective_fields (Phase 2 - prepares for future provider major versions):**
4848
- If data source uses `use_effective_fields = true`:
4949
- `*_specs` returns configured values (client-provided intent).
5050
- `effective_*_specs` returns actual provisioned values (Atlas-managed reality).
51-
- **BREAKING CHANGE:** Must switch from `*_specs` to `effective_*_specs` for actual values.
52-
- Prepares for provider v3.x where this becomes default behavior.
51+
- Module users must switch from `*_specs` to `effective_*_specs` for actual values.
52+
- Prepares for future provider major versions where this becomes default behavior.
5353
- Clear separation between what you configured and what Atlas provisioned.
5454

5555
## Complete Migration Example

0 commit comments

Comments
 (0)