From f44531b75fbba4c0cdd2e7c1ccc2ead983f5dcda Mon Sep 17 00:00:00 2001 From: Andrea Angiolillo Date: Mon, 28 Aug 2023 18:50:57 +0100 Subject: [PATCH] fix: INTMDB-1017 - Updated alert configuration schema with required params (#1421) --- ..._resource_mongodbatlas_alert_configuration.go | 10 +++++----- ...urce_mongodbatlas_alert_configuration_test.go | 6 ------ website/docs/r/alert_configuration.html.markdown | 16 ++++++---------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go index c0961cf253..8009cc50f5 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go @@ -166,13 +166,13 @@ func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "field_name": schema.StringAttribute{ - Optional: true, + Required: true, }, "operator": schema.StringAttribute{ - Optional: true, + Required: true, }, "value": schema.StringAttribute{ - Optional: true, + Required: true, }, }, }, @@ -184,7 +184,7 @@ func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "metric_name": schema.StringAttribute{ - Optional: true, + Required: true, }, "operator": schema.StringAttribute{ Optional: true, @@ -330,7 +330,7 @@ func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe }, }, "type_name": schema.StringAttribute{ - Optional: true, + Required: true, Validators: []validator.String{ stringvalidator.OneOf("EMAIL", "SMS", pagerDuty, "SLACK", "DATADOG", opsGenie, victorOps, diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index 1f90f76a0f..e9178b9af3 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -59,8 +58,6 @@ func TestAccConfigRSAlertConfiguration_EmptyMetricThresholdConfig(t *testing.T) Steps: []resource.TestStep{ { Config: testAccMongoDBAtlasAlertConfigurationConfigEmptyMetricThresholdConfig(orgID, projectName, true), - // metric threshold is not created so state is inconsistent with plan - ExpectError: regexp.MustCompile("Error: Provider produced inconsistent result after apply"), }, }, }) @@ -847,9 +844,6 @@ resource "mongodbatlas_alert_configuration" "test" { roles = ["GROUP_OWNER"] } - - metric_threshold_config {} - threshold_config { operator = "LESS_THAN" threshold = 72 diff --git a/website/docs/r/alert_configuration.html.markdown b/website/docs/r/alert_configuration.html.markdown index 53a9b8ae6b..19b98701ff 100644 --- a/website/docs/r/alert_configuration.html.markdown +++ b/website/docs/r/alert_configuration.html.markdown @@ -132,7 +132,7 @@ resource "mongodbatlas_alert_configuration" "test" { ### Matchers Rules to apply when matching an object against this alert configuration. Only entities that match all these rules are checked for an alert condition. You can filter using the matchers array only when the eventTypeName specifies an event for a host, replica set, or sharded cluster. -* `field_name` - Name of the field in the target object to match on. +* `field_name` - (Required) Name of the field in the target object to match on. | Host alerts | Replica set alerts | Sharded cluster alerts | |:---------- |:------------- |:------ | @@ -144,13 +144,9 @@ Rules to apply when matching an object against this alert configuration. Only en - All other types of alerts do not support matchers. +All other types of alerts do not support matchers. -* `operator` - If omitted, the configuration is disabled. -* `value` - If omitted, the configuration is disabled. - - -* `operator` - The operator to test the field’s value. +* `operator` - (Required) The operator to test the field’s value. Accepted values are: - `EQUALS` - `NOT_EQUALS` @@ -160,7 +156,7 @@ Rules to apply when matching an object against this alert configuration. Only en - `ENDS_WITH` - `REGEX` -* `value` - Value to test with the specified operator. If `field_name` is set to TYPE_NAME, you can match on the following values: +* `value` - (Required) Value to test with the specified operator. If `field_name` is set to TYPE_NAME, you can match on the following values: - `PRIMARY` - `SECONDARY` - `STANDALONE` @@ -170,7 +166,7 @@ Rules to apply when matching an object against this alert configuration. Only en ### Metric Threshold Config (`metric_threshold_config`) The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD` -* `metric_name` - Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) +* `metric_name` - (Required) Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) * `operator` - Operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` @@ -213,7 +209,7 @@ List of notifications to send when an alert condition is detected. * `sms_enabled` - Flag indicating if text message notifications should be sent to this user's mobile phone. This flag is only valid if `type_name` is set to `ORG`, `GROUP`, or `USER`. * `team_id` - Unique identifier of a team. * `team_name` - Label for the team that receives this notification. -* `type_name` - Type of alert notification. +* `type_name` - (Required) Type of alert notification. Accepted values are: - `DATADOG` - `EMAIL`