Skip to content

fix: Emit warning when use effective fields is used#4405

Draft
marcabreracast wants to merge 5 commits intomasterfrom
CLOUDP-388940_Emit_Warning_When_UseEffectiveFields_Is_Used
Draft

fix: Emit warning when use effective fields is used#4405
marcabreracast wants to merge 5 commits intomasterfrom
CLOUDP-388940_Emit_Warning_When_UseEffectiveFields_Is_Used

Conversation

@marcabreracast
Copy link
Copy Markdown
Collaborator

@marcabreracast marcabreracast commented Apr 27, 2026

Description

Emits a Terraform warning during ModifyPlan when all three conditions are met:

  • use_effective_fields = true
  • Auto-scaling is enabled in the config (compute_enabled = true or disk_gb_enabled = true)
  • The user changes the following fields: instance_size, disk_size_gb, or disk_iops

In this combination, the Atlas API silently ignores the spec change, the new values are stored in Terraform state but the cluster is never modified, producing a false "1 changed" result with no feedback. The warning makes this visible and directs the user to temporarily disable auto-scaling to apply the change.

Link to any related issue(s): https://jira.mongodb.org/browse/CLOUDP-388940

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fix and verified my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Testing

The warning itself cannot be asserted programmatically. Manual verification is therefore required.

Manual test steps

Further comments

Copilot AI review requested due to automatic review settings April 27, 2026 14:27
@marcabreracast marcabreracast changed the title fix: emit warning when use effective fields is used feat: emit warning when use effective fields is used Apr 27, 2026
@marcabreracast marcabreracast changed the title feat: emit warning when use effective fields is used fix: Emit warning when use effective fields is used Apr 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the advanced cluster plan modification logic to warn users when use_effective_fields = true is combined with auto-scaling and the configuration changes spec fields that Atlas will ignore.

Changes:

  • Emit a Terraform warning when use_effective_fields=true, auto-scaling is enabled, and instance_size / disk_size_gb / disk_iops change.
  • Refactor autoScalingUsed to accept a single cluster model and adjust auto-scaling keep-unknown detection accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/service/advancedcluster/plan_modifier.go
Comment on lines +61 to 64
autoScalingFields := determineKeepUnknownsAutoScaling(ctx, diags, state, plan)
keepUnknown = append(keepUnknown, autoScalingFields...)
emitWarningIfSpecChangedWithAutoScaling(ctx, diags, plan, attributeChanges)
schemafunc.CopyUnknowns(ctx, state, plan, keepUnknown, nil)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

This PR introduces new user-facing behavior (a warning when use_effective_fields=true, auto-scaling is enabled, and spec fields change), but there’s no automated coverage asserting when the warning should/shouldn’t be emitted. Adding a focused unit test around emitWarningIfSpecChangedWithAutoScaling (or exercising it via an existing plan modifier test harness) would help prevent regressions and false positives.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There's not a way of asserting warnings into the test framework. The code path is exercised by the existing TestAccAdvancedCluster_effectiveComputeAutoScalingInstanceSize test, which runs the exact scenario. A panic or logic error would be caught there.

Behaviour of the warning is documented and manual tests are done in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants