Skip to content

Conversation

@lantoli
Copy link
Member

@lantoli lantoli commented Nov 21, 2025

Description

Use use_effective_fields boolean attribute in resource

  • Have tests in effective_fields_test.go as resource_test.go already has 3,000 lines.
  • This PR only has basic tests, more comprehensive tests will follow in other PRs

Link to any related issue(s): CLOUDP-360426

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 fmt and formatted 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.

Further comments

@lantoli lantoli changed the base branch from master to CLOUDP-313272-dev-effective-fields November 21, 2025 08:43
@lantoli lantoli closed this Nov 21, 2025
@lantoli lantoli reopened this Nov 21, 2025
…flag_resource

* CLOUDP-313272-dev-effective-fields:
  chore: Updates Atlas Go SDK (#3907)
  doc: Updates Terraform Compatibility Matrix documentation (#3905)
  chore: Adds panic for deprecated SDKv2 resource operations (#3900)
…flag_resource

* CLOUDP-313272-dev-effective-fields:
  chore: Support resource deprecation in autogen (#3909)
  chore: Support configuration for update marshalling to send null for list/set types (#3908)
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/flexcluster"
)

func CreateCluster(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, req *admin.ClusterDescription20240805, waitParams *ClusterWaitParams) *admin.ClusterDescription20240805 {
Copy link
Member Author

@lantoli lantoli Nov 24, 2025

Choose a reason for hiding this comment

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

moved to resource.go as it's only used there now

@lantoli lantoli force-pushed the CLOUDP-360426_flag_resource branch from 3d5ebd7 to 1bc1411 Compare November 25, 2025 08:54
@lantoli lantoli force-pushed the CLOUDP-360426_flag_resource branch from 1bc1411 to e50baa9 Compare November 25, 2025 16:54
@lantoli lantoli marked this pull request as ready for review November 25, 2025 20:16
@lantoli lantoli requested a review from a team as a code owner November 25, 2025 20:16
@lantoli lantoli requested a review from a team as a code owner November 25, 2025 20:16
Copilot AI review requested due to automatic review settings November 25, 2025 20:16
@github-actions
Copy link
Contributor

APIx bot: a message has been sent to Docs Slack channel

Copy link
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 adds support for the use_effective_fields boolean attribute in the advanced cluster resource, which controls how hardware specification fields are returned from the API. When enabled, this feature helps eliminate plan drift during cluster auto-scaling operations by returning client-provided specifications rather than current scaled values.

Key changes:

  • Added use_effective_fields validation to prevent usage with Flex or Tenant clusters
  • Propagated the use_effective_fields parameter through API calls for create, read, update, and list operations
  • Renamed internal functions to use lowercase naming convention

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/service/advancedcluster/validate_schema.go Added validator to restrict use_effective_fields to dedicated clusters only
internal/service/advancedcluster/schema.go Added validator to the use_effective_fields attribute
internal/service/advancedcluster/resource.go Updated to pass use_effective_fields to API calls and renamed helper functions
internal/service/advancedcluster/common_admin_sdk.go Moved cluster create/update functions and added use_effective_fields to API calls
internal/service/advancedcluster/common_await_changes.go Added UseEffectiveFields to ClusterWaitParams and propagated through wait logic
internal/service/advancedcluster/common.go Added isTenant helper function and renamed IsFlex to isFlex
internal/service/advancedcluster/model_to_ClusterDescription20240805.go Renamed conversion functions to remove 20240805 suffix
internal/service/advancedcluster/data_source.go Updated to pass use_effective_fields to read operations
internal/service/advancedcluster/plural_data_source.go Added use_effective_fields parameter to list clusters API call
internal/service/advancedcluster/effective_fields_test.go Added basic tests for use_effective_fields functionality
internal/service/advancedcluster/resource_test.go Updated test helper function signature
docs/resources/advanced_cluster.md Updated documentation to clarify Flex/Tenant restriction and auto-scaling behavior
docs/data-sources/advanced_cluster.md Updated documentation to mention Flex/Tenant restriction
docs/data-sources/advanced_clusters.md Updated documentation to mention Flex/Tenant restriction
.github/workflows/code-health.yml Temporarily disabled job dependencies for testing
.github/workflows/acceptance-tests-runner.yml Temporarily filtered tests to only run effective fields tests

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

exit 1
call-acceptance-tests-workflow:
needs: [build, lint, shellcheck, unit-test, generate-doc-check]
# needs: [build, lint, shellcheck, unit-test, generate-doc-check] # TEMPORARY: Don't merge, will be reverted in the last commit before merging
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Commented-out job dependency creates a risk if this temporary change is merged. Consider using a feature flag or environment variable check instead of commenting out the dependency.

Suggested change
# needs: [build, lint, shellcheck, unit-test, generate-doc-check] # TEMPORARY: Don't merge, will be reverted in the last commit before merging
needs: [build, lint, shellcheck, unit-test, generate-doc-check]

Copilot uses AI. Check for mistakes.
Comment on lines +430 to +431
# TEMPORARY: Don't merge, will be reverted in the last commit before merging
ACCTEST_REGEX_RUN: '^TestAccAdvancedCluster_effective'
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Temporary test filter creates a risk if merged. The hardcoded regex replaces conditional logic and would cause only effective fields tests to run in all scenarios.

Suggested change
# TEMPORARY: Don't merge, will be reverted in the last commit before merging
ACCTEST_REGEX_RUN: '^TestAccAdvancedCluster_effective'
# Run all advanced cluster acceptance tests
ACCTEST_REGEX_RUN: ''

Copilot uses AI. Check for mistakes.
t.Fatalf("cluster %s not found in %s", clusterName, projectID)
}
advancedcluster.AwaitChanges(t.Context(), acc.MongoDBClient, &advancedcluster.ClusterWaitParams{
_ = advancedcluster.AwaitChanges(t.Context(), acc.MongoDBClient, &advancedcluster.ClusterWaitParams{
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

[nitpick] Using blank identifier to explicitly ignore the return value is appropriate here since AwaitChanges reports errors through the diagnostics parameter, but the function call appears incomplete without handling potential diagnostic errors after the call. Ensure diagnostics are checked if needed.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@jwilliams-mongo jwilliams-mongo left a comment

Choose a reason for hiding this comment

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

few minor comments on clarifying what happens for tenant/flex clusters

* `project_id` - (Required) The unique ID for the project to create the cluster.
* `name` - (Required) Name of the cluster as it appears in Atlas. Once the cluster is created, its name cannot be changed.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. **Note:** Effective specs (`effective_electable_specs`, `effective_read_only_specs`, `effective_analytics_specs`) are always returned regardless of the flag value and always report the **current** hardware specifications. See the resource documentation for [Auto-Scaling with Effective Fields](../resources/advanced_cluster.md#auto-scaling-with-effective-fields) for more details.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. It does not apply to tenant or flex clusters. **Note:** Effective specs (`effective_electable_specs`, `effective_read_only_specs`, `effective_analytics_specs`) are always returned regardless of the flag value and always report the **current** hardware specifications. See the resource documentation for [Auto-Scaling with Effective Fields](../resources/advanced_cluster.md#auto-scaling-with-effective-fields) for more details.
Copy link
Collaborator

Choose a reason for hiding this comment

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

when we say "does not apply": are these fields not returned for M0/Flex? are they null? returned with pre-selected values?


* `project_id` - (Required) The unique ID for the project to get the clusters.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. **Note:** Effective specs (`effective_electable_specs`, `effective_read_only_specs`, `effective_analytics_specs`) are always returned regardless of the flag value and always report the **current** hardware specifications. See the resource documentation for [Auto-Scaling with Effective Fields](../resources/advanced_cluster.md#auto-scaling-with-effective-fields) for more details.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. It does not apply to tenant or flex clusters. **Note:** Effective specs (`effective_electable_specs`, `effective_read_only_specs`, `effective_analytics_specs`) are always returned regardless of the flag value and always report the **current** hardware specifications. See the resource documentation for [Auto-Scaling with Effective Fields](../resources/advanced_cluster.md#auto-scaling-with-effective-fields) for more details.
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

* `config_server_management_mode` - (Optional) Config Server Management Mode for creating or updating a sharded cluster. Valid values are `ATLAS_MANAGED` (default) and `FIXED_TO_DEDICATED`. When configured as `ATLAS_MANAGED`, Atlas may automatically switch the cluster's config server type for optimal performance and savings. When configured as `FIXED_TO_DEDICATED`, the cluster will always use a dedicated config server. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).
- `delete_on_create_timeout`- (Optional) Indicates whether to delete the resource being created if a timeout is reached when waiting for completion. When set to `true` and timeout occurs, it triggers the deletion and returns immediately without waiting for deletion to complete. When set to `false`, the timeout will not trigger resource deletion. If you suspect a transient error when the value is `true`, wait before retrying to allow resource deletion to finish. Default is `true`.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. This opt-in feature enhances auto-scaling workflows by eliminating the need for `lifecycle.ignore_changes` blocks and preventing plan drift from Atlas-managed changes. This attribute will be deprecated in provider version 2.x and removed in 3.x when the new behavior becomes default. See [Auto-Scaling with Effective Fields](#auto-scaling-with-effective-fields) for more details.
* `use_effective_fields` - (Optional) Controls how hardware specification fields are returned in the response. When set to true, the non-effective specs (`electable_specs`, `read_only_specs`, `analytics_specs`) fields return the hardware specifications that the client provided. When set to false (default), the non-effective specs fields show the **current** hardware specifications. Cluster auto-scaling is the primary cause for differences between initial and current hardware specifications. This opt-in feature enhances auto-scaling workflows by eliminating the need for `lifecycle.ignore_changes` blocks and preventing plan drift from Atlas-managed changes. It does not apply to tenant or flex clusters. This attribute will be deprecated in provider version 2.x and removed in 3.x when the new behavior becomes default. See [Auto-Scaling with Effective Fields](#auto-scaling-with-effective-fields) for more details.
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants