Skip to content

Conversation

EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Feb 25, 2025

Description

Link to any related issue(s): CLOUDP-302586 & #3103

Updated context:

  • The API now returns with_default_alert_settings, before this was only set on create and never returned.
  • This can impact users:

During Plan

  • If the user did not define the attribute, the default value of true should match what the API returns, covered by: TestMigProject_basic
  • If the user defined the attribute in their config during create and never made changes, there should be no plan changes, covered by: TestMigProject_withTrueDefaultAlertSettings
  • same as previous but with false value, covered by: TestMigProject_withFalseDefaultAlertSettings
  • If the user created the project and later changed the value, the API and the config will differ and they will see an error when they run a terraform plan, see the error message below.

The user will be forced to update their config to match the API value, otherwise they will get inconsistent result value.

During Update

Before this change, Terraform allowed updates to with_default_alert_settings, but now we will raise an error:

Error message:

Example when the user has modified the attribute value after creation (created with with_default_alerts_settings= true)

resource "mongodbatlas_project" "this" {
  org_id = var.org_id
  name   = "analytics_test"
  with_default_alerts_settings = false
}
Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: with_default_alerts_settings cannot be updated or set after import, remove it from the configuration or use the state value (see below).
│ 
│   with mongodbatlas_project.this,
│   on main.tf line 21, in resource "mongodbatlas_project" "this":
│   21: resource "mongodbatlas_project" "this" {
│ 
│ The current state value is true
  • As soon as the user removes/updates the value, they will get No Plan Changes

During Import

Import works now due to the API change, and the experience will be the same as described in During Plan above

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

@github-actions github-actions bot added the bug label Feb 25, 2025
@EspenAlbert EspenAlbert marked this pull request as ready for review February 25, 2025 10:18
@EspenAlbert EspenAlbert requested review from a team as code owners February 25, 2025 10:18
Copy link
Contributor

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

…ore in project tests when it is not set to `false` in earlier steps
@marcosuma
Copy link
Collaborator

@EspenAlbert nit: can we have a why in the summary section to explain the change? also let's hold this merge until we have a conversation with the upstream team (if we did, we should connect the CLOUDPs and understand the why on their side)

Copy link
Contributor

@kanchana-mongodb kanchana-mongodb left a comment

Choose a reason for hiding this comment

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

LGTM

@EspenAlbert
Copy link
Collaborator Author

Will get back to this on Wednesday

planmodifier.Bool
}

func CreateOnlyAttributePlanModifier() Modifier {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a comment on what this plan modifier does & why it's needed?

Copy link
Contributor

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label Mar 12, 2025
@EspenAlbert EspenAlbert added the not_stale Not stale issue or PR label Mar 12, 2025
Copy link
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

@EspenAlbert let's hold on this one. I am not too convinced we are doing the right thing in adding more complexity to handle something like this. Let's chat in today's tech sync.

@EspenAlbert EspenAlbert changed the title fix: Sets default value for WithDefaultAlertsSettings during state import test: Ensures project withDefaultAlertsSettings works with import and introduce create_only plan modifier Jul 11, 2025
@github-actions github-actions bot removed the bug label Jul 11, 2025
@Copilot Copilot AI review requested due to automatic review settings August 26, 2025 11:05
Copy link
Contributor

@Copilot 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 introduces a create-only plan modifier for the with_default_alerts_settings attribute in MongoDB Atlas projects to align with API changes that now return this value after creation. The change prevents users from updating this attribute after project creation while maintaining backward compatibility.

  • Implements create-only behavior for with_default_alerts_settings attribute with proper error messaging
  • Updates test infrastructure to validate import functionality and plan behavior
  • Refactors plan modifiers from generic "non-updatable" to specific "create-only" pattern

Reviewed Changes

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

Show a summary per file
File Description
internal/service/project/resource_project_schema.go Replaces default value with create-only plan modifier for with_default_alerts_settings
internal/service/project/resource_project_test.go Enhances tests to validate create-only behavior and import scenarios
internal/service/project/resource_project_migration_test.go Updates migration tests to use parameterized alert settings configurations
internal/common/customplanmodifier/create_only.go Implements new create-only plan modifier with default value support
internal/common/customplanmodifier/non_updatable.go Removes old non-updatable plan modifier
internal/testutil/acc/project.go Removes with_default_alerts_settings from test configuration helper
internal/service/flexcluster/resource_schema.go Updates to use new create-only plan modifier
docs/resources/project.md Updates documentation to clarify create-only nature of the attribute

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not_stale Not stale issue or PR stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants