-
Notifications
You must be signed in to change notification settings - Fork 208
feat: Adds support for alertConfiguration.severityOverride attribute #3795
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
Changes from 3 commits
9e62e14
ae82057
4adac12
e716664
0784906
ee6b47f
316f9ca
f013ce5
c6e2dec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ```release-note:enhancement | ||
| data-source/mongodbatlas_alert_configuration: Adds `severity_override` attribute | ||
| ``` | ||
|
|
||
| ```release-note:enhancement | ||
ciprian-tibulca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resource/mongodbatlas_alert_configuration: Adds `severity_override` attribute | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ type TfAlertConfigurationRSModel struct { | |
| EventType types.String `tfsdk:"event_type"` | ||
| Created types.String `tfsdk:"created"` | ||
| Updated types.String `tfsdk:"updated"` | ||
| SeverityOverride types.String `tfsdk:"severity_override"` | ||
| Matcher []TfMatcherModel `tfsdk:"matcher"` | ||
| MetricThresholdConfig []TfMetricThresholdConfigModel `tfsdk:"metric_threshold_config"` | ||
| ThresholdConfig []TfThresholdConfigModel `tfsdk:"threshold_config"` | ||
|
|
@@ -154,6 +155,9 @@ func (r *alertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe | |
| boolplanmodifier.UseStateForUnknown(), | ||
| }, | ||
| }, | ||
| "severity_override": schema.StringAttribute{ | ||
| Optional: true, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to double check: This is never returned by the API unless defined by the user? How do the user reset the attribute? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
correct
as of now, this flag cannot be cleared (if not set in the PUT request body it won't be reset). Same happens from UI too, I will open a ticket with the owning team. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, | ||
| }, | ||
| Blocks: map[string]schema.Block{ | ||
| "matcher": schema.ListNestedBlock{ | ||
|
|
@@ -381,11 +385,12 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe | |
| projectID := alertConfigPlan.ProjectID.ValueString() | ||
|
|
||
| apiReq := &admin.GroupAlertsConfig{ | ||
| EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), | ||
| Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), | ||
| Matchers: NewMatcherList(alertConfigPlan.Matcher), | ||
| MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), | ||
| Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), | ||
| EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), | ||
| Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), | ||
| Matchers: NewMatcherList(alertConfigPlan.Matcher), | ||
| MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), | ||
| Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), | ||
| SeverityOverride: alertConfigPlan.SeverityOverride.ValueStringPointer(), | ||
| } | ||
|
|
||
| notifications, err := NewNotificationList(alertConfigPlan.Notification) | ||
|
|
@@ -488,6 +493,10 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe | |
| apiReq.Matchers = NewMatcherList(alertConfigPlan.Matcher) | ||
| } | ||
|
|
||
| if !alertConfigPlan.SeverityOverride.Equal(alertConfigState.SeverityOverride) { | ||
| apiReq.SeverityOverride = alertConfigPlan.SeverityOverride.ValueStringPointer() | ||
| } | ||
|
|
||
| // Always refresh structure to handle service keys being obfuscated coming back from read API call | ||
| notifications, err := NewNotificationList(alertConfigPlan.Notification) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { | |
| checkExists(resourceName), | ||
| resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
| resource.TestCheckResourceAttr(resourceName, "notification.#", "2"), | ||
| resource.TestCheckNoResourceAttr(resourceName, "severity_override"), | ||
| // Data source checks | ||
| checkExists(dataSourceName), | ||
| resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID), | ||
|
|
@@ -47,6 +48,7 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { | |
| resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"), | ||
| resource.TestCheckResourceAttr(dataSourceName, "metric_threshold_config.#", "1"), | ||
| resource.TestCheckResourceAttr(dataSourceName, "threshold_config.#", "0"), | ||
| resource.TestCheckNoResourceAttr(dataSourceName, "severity_override"), | ||
| ), | ||
| }, | ||
| { | ||
|
|
@@ -55,6 +57,7 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { | |
| checkExists(resourceName), | ||
| resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
| resource.TestCheckResourceAttr(resourceName, "notification.#", "2"), | ||
| resource.TestCheckNoResourceAttr(resourceName, "severity_override"), | ||
| // Data source checks | ||
| checkExists(dataSourceName), | ||
| resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID), | ||
|
|
@@ -63,6 +66,7 @@ func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { | |
| resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"), | ||
| resource.TestCheckResourceAttr(dataSourceName, "metric_threshold_config.#", "1"), | ||
| resource.TestCheckResourceAttr(dataSourceName, "threshold_config.#", "0"), | ||
| resource.TestCheckNoResourceAttr(dataSourceName, "severity_override"), | ||
| ), | ||
| }, | ||
| { | ||
|
|
@@ -566,6 +570,32 @@ func TestAccConfigRSAlertConfiguration_withVictorOps(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| func TestAccConfigRSAlertConfiguration_withSeverityOverride(t *testing.T) { | ||
| var ( | ||
| projectID = acc.ProjectIDExecution(t) | ||
| ) | ||
|
|
||
| resource.ParallelTest(t, resource.TestCase{ | ||
| PreCheck: func() { acc.PreCheckBasic(t) }, | ||
| ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
| CheckDestroy: checkDestroy(), | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: configWithSeverityOverride(projectID, "WARNING"), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
|
Comment on lines
582
to
585
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add an additional step modifying the value, and also capture behaviour of what happens when attribute is removed (related to Espen thread). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the step, byt it's currently commented (due to https://jira.mongodb.org/browse/CLOUDP-353933) |
||
| checkExists(resourceName), | ||
| resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
ciprian-tibulca marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resource.TestCheckResourceAttr(resourceName, "severity_override", "WARNING"), | ||
| // Data source checks | ||
| checkExists(dataSourceName), | ||
| resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID), | ||
| resource.TestCheckResourceAttr(dataSourceName, "severity_override", "WARNING"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func checkExists(resourceName string) resource.TestCheckFunc { | ||
| return func(s *terraform.State) error { | ||
| rs, ok := s.RootModule().Resources[resourceName] | ||
|
|
@@ -1039,6 +1069,28 @@ func configWithEmptyOptionalBlocks(projectID string) string { | |
| `, projectID) | ||
| } | ||
|
|
||
| func configWithSeverityOverride(projectID, severity string) string { | ||
| return fmt.Sprintf(` | ||
| resource "mongodbatlas_alert_configuration" "test" { | ||
| project_id = %[1]q | ||
| enabled = true | ||
| event_type = "NO_PRIMARY" | ||
| severity_override = %[2]q | ||
|
|
||
| notification { | ||
| type_name = "EMAIL" | ||
| interval_min = 60 | ||
| email_address = "[email protected]" | ||
| } | ||
| } | ||
|
|
||
| data "mongodbatlas_alert_configuration" "test" { | ||
| project_id = mongodbatlas_alert_configuration.test.project_id | ||
| alert_configuration_id = mongodbatlas_alert_configuration.test.id | ||
| } | ||
| `, projectID, severity) | ||
| } | ||
|
|
||
| func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) { | ||
| var ( | ||
| projectID = acc.ProjectIDExecution(t) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.