Skip to content

fix: Sets default value for WithDefaultAlertsSettings during state import #3105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3105.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/mongodbatlas_project: Sets default value for `with_default_alerts_settings` during state import
```
10 changes: 7 additions & 3 deletions internal/service/project/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ func (r *projectRS) ImportState(ctx context.Context, req resource.ImportStateReq
}

func updatePlanFromConfig(projectPlanNewPtr, projectPlan *TFProjectRSModel) {
// we need to reset defaults from what was previously in the state:
// https://discuss.hashicorp.com/t/boolean-optional-default-value-migration-to-framework/55932
projectPlanNewPtr.WithDefaultAlertsSettings = projectPlan.WithDefaultAlertsSettings
// After import the state&plan will be null so we set to true (default value)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The user will still get a plan change after import if they have set with_default_alert_settings=false in their config. But we don't have access to that information in the import

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is still a possibility, I'm thinking if we should even implement this fix. This sounds like it should be expected behavior that WithDefaultAlertsSettings will not be set during import and maybe something we can call out in our documentation instead.

I'd find it harder to explain to users why import shows an update if with_default_alert_settings=false in their config but works when it's true.

if projectPlanNewPtr.WithDefaultAlertsSettings.IsNull() && projectPlan.WithDefaultAlertsSettings.IsNull() {
projectPlanNewPtr.WithDefaultAlertsSettings = types.BoolValue(true)
} else {
// Force value from plan as this is not returned from the API to avoid inconsistent result errors
Copy link
Collaborator

Choose a reason for hiding this comment

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

it just feels a workaround from an API limitation, have we reached out to the team owning this feature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I understand is a create-only parameter that has a side effect of creating alert settings, but I'll check with upstream. Api Docs

projectPlanNewPtr.WithDefaultAlertsSettings = projectPlan.WithDefaultAlertsSettings
}
projectPlanNewPtr.ProjectOwnerID = projectPlan.ProjectOwnerID
if projectPlan.Tags.IsNull() && len(projectPlanNewPtr.Tags.Elements()) == 0 {
projectPlanNewPtr.Tags = types.MapNull(types.StringType)
Expand Down