-
Notifications
You must be signed in to change notification settings - Fork 209
fix: Removes interval_min validation blocking notification type updates in alert_configuration
#3882
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
EspenAlbert
wants to merge
2
commits into
master
Choose a base branch
from
CLOUDP-358194_alert_config_min_interval_error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−10
Open
fix: Removes interval_min validation blocking notification type updates in alert_configuration
#3882
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:bug | ||
| resource/mongodbatlas_alert_configuration: Fixes issue preventing updates from notification types supporting `interval_min` (e.g., MICROSOFT_TEAMS) to types that don't support it (PAGER_DUTY, OPS_GENIE, VICTOR_OPS) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
internal/service/alertconfiguration/validator_interval_min.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package alertconfiguration | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
| "github.com/hashicorp/terraform-plugin-framework/path" | ||
| "github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
| ) | ||
|
|
||
| // IntervalMinValidator validates that interval_min is not set for notification types | ||
| // that don't support it (PAGER_DUTY, OPS_GENIE, VICTOR_OPS). | ||
| // | ||
| // API-level validation cannot catch this error because when the notification type | ||
| // doesn't support interval_min, the nested_type in the API payload omits the field, | ||
| // so it's never sent to the API. Client-side validation ensures users get immediate | ||
| // feedback during Terraform's plan phase. | ||
| type IntervalMinValidator struct{} | ||
|
|
||
| func (v IntervalMinValidator) Description(_ context.Context) string { | ||
| return "'interval_min' must not be set if type_name is 'PAGER_DUTY', 'OPS_GENIE' or 'VICTOR_OPS'" | ||
| } | ||
|
|
||
| func (v IntervalMinValidator) MarkdownDescription(ctx context.Context) string { | ||
| return v.Description(ctx) | ||
| } | ||
|
|
||
| func (v IntervalMinValidator) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) { | ||
| // If the value is unknown/null/0, there is nothing to validate. | ||
| if req.ConfigValue.ValueInt64() <= 0 { | ||
EspenAlbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return | ||
| } | ||
|
|
||
| // Parse the path to find which notification index we're validating | ||
| // Path format: notification[0].interval_min | ||
| pathStr := req.Path.String() | ||
| notificationIndex := -1 | ||
|
|
||
| // Extract the index from the path (e.g., "notification[0]" -> 0) | ||
| if idxStart := strings.Index(pathStr, "["); idxStart != -1 { | ||
| if idxEnd := strings.Index(pathStr[idxStart:], "]"); idxEnd != -1 { | ||
| idxStr := pathStr[idxStart+1 : idxStart+idxEnd] | ||
| if idx, err := strconv.Atoi(idxStr); err == nil { | ||
| notificationIndex = idx | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If we couldn't parse the index, skip validation | ||
| if notificationIndex < 0 { | ||
| return | ||
| } | ||
|
|
||
| // Get the entire notification list from config | ||
| var notifications []TfNotificationModel | ||
| diags := req.Config.GetAttribute(ctx, path.Root("notification"), ¬ifications) | ||
| if diags.HasError() { | ||
| // If we can't read notifications, skip validation (might be unknown during plan) | ||
| return | ||
| } | ||
|
|
||
| // Check if we have the notification at the parsed index | ||
| if notificationIndex >= len(notifications) { | ||
| return | ||
| } | ||
|
|
||
| notification := notifications[notificationIndex] | ||
| typeNameValue := notification.TypeName.ValueString() | ||
| // Check if the type_name is one of the unsupported types | ||
| if strings.EqualFold(typeNameValue, pagerDuty) || | ||
| strings.EqualFold(typeNameValue, opsGenie) || | ||
| strings.EqualFold(typeNameValue, victorOps) { | ||
| resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( | ||
| req.Path, | ||
| v.Description(ctx), | ||
| fmt.Sprintf("%d", req.ConfigValue.ValueInt64()), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func ValidIntervalMin() validator.Int64 { | ||
| return IntervalMinValidator{} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.