diff --git a/newrelic/resource_newrelic_nrql_alert_condition.go b/newrelic/resource_newrelic_nrql_alert_condition.go index 5e28793e7..5fe577b88 100644 --- a/newrelic/resource_newrelic_nrql_alert_condition.go +++ b/newrelic/resource_newrelic_nrql_alert_condition.go @@ -98,6 +98,12 @@ func termSchema() *schema.Resource { }, }, }, + "disable_health_status_reporting": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Violations will not change system health status for this term.", + }, }, } } diff --git a/newrelic/resource_newrelic_nrql_alert_condition_test.go b/newrelic/resource_newrelic_nrql_alert_condition_test.go index 18e817010..795f6f91f 100644 --- a/newrelic/resource_newrelic_nrql_alert_condition_test.go +++ b/newrelic/resource_newrelic_nrql_alert_condition_test.go @@ -612,6 +612,28 @@ func TestAccNewRelicNrqlAlertCondition_StaticConditionPrediction(t *testing.T) { }) } +func TestAccNewRelicNrqlAlertCondition_StaticConditionDisableHealthStatusReporting(t *testing.T) { + resourceName := "newrelic_nrql_alert_condition.foo" + rName := acctest.RandString(5) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEnvVars(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckNewRelicNrqlAlertConditionDestroy, + Steps: []resource.TestStep{ + // Test: Create + { + Config: testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting( + rName, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicNrqlAlertConditionExists(resourceName), + ), + }, + }, + }) +} + func TestAccNewRelicNrqlAlertCondition_StaticConditionExpectedTermination(t *testing.T) { resourceName := "newrelic_nrql_alert_condition.foo" rName := acctest.RandString(5) @@ -1423,3 +1445,36 @@ resource "newrelic_nrql_alert_condition" "foo" { } `, name, predictBy) } + +func testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting( + name string, +) string { + return fmt.Sprintf(` +resource "newrelic_alert_policy" "foo" { + name = "tf-test-%[1]s" +} + +resource "newrelic_nrql_alert_condition" "foo" { + policy_id = newrelic_alert_policy.foo.id + + name = "tf-test-%[1]s" + type = "static" + enabled = false + violation_time_limit_seconds = 3600 + aggregation_delay = 120 + aggregation_method = "event_flow" + + nrql { + query = "SELECT uniqueCount(hostname) FROM ComputeSample" + } + + critical { + operator = "below" + threshold = 0 + threshold_duration = 120 + threshold_occurrences = "ALL" + disable_health_status_reporting = true + } +} +`, name) +} diff --git a/newrelic/structures_newrelic_nrql_alert_condition.go b/newrelic/structures_newrelic_nrql_alert_condition.go index f66a1a86a..0ec018261 100644 --- a/newrelic/structures_newrelic_nrql_alert_condition.go +++ b/newrelic/structures_newrelic_nrql_alert_condition.go @@ -286,6 +286,11 @@ func expandNrqlConditionTerm(term map[string]interface{}, conditionType, priorit ThresholdOccurrences: *thresholdOccurrences, } + if term["disable_health_status_reporting"] != nil { + disableHealthStatusReporting := term["disable_health_status_reporting"].(bool) + expandedTerm.DisableHealthStatusReporting = &disableHealthStatusReporting + } + if conditionType == "baseline" { return &expandedTerm, nil } @@ -781,6 +786,10 @@ func flattenNrqlTerms(terms []alerts.NrqlConditionTerm, configTerms []interface{ dst["threshold_occurrences"] = strings.ToLower(string(term.ThresholdOccurrences)) } + if term.DisableHealthStatusReporting != nil { + dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting + } + out = append(out, dst) } @@ -808,6 +817,10 @@ func handleImportFlattenNrqlTerms(terms []alerts.NrqlConditionTerm) []map[string dst["prediction"] = []interface{}{predictionBlockContents} } + if term.DisableHealthStatusReporting != nil { + dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting + } + out = append(out, dst) } @@ -828,8 +841,9 @@ func getConfiguredTerms(configTerms []interface{}) []map[string]interface{} { "time_function": t["time_function"], // NerdGraph fields - "threshold_duration": t["threshold_duration"], - "threshold_occurrences": t["threshold_occurrences"], + "threshold_duration": t["threshold_duration"], + "threshold_occurrences": t["threshold_occurrences"], + "disable_health_status_reporting": t["disable_health_status_reporting"], } predictionSet := t["prediction"].(*schema.Set) diff --git a/newrelic/structures_newrelic_nrql_alert_condition_test.go b/newrelic/structures_newrelic_nrql_alert_condition_test.go index 0a475a46f..cc9e27e6a 100644 --- a/newrelic/structures_newrelic_nrql_alert_condition_test.go +++ b/newrelic/structures_newrelic_nrql_alert_condition_test.go @@ -17,8 +17,9 @@ import ( ) var ( - testThresholdLow = 1.0 - testThresholdHigh = 10.9 + testThresholdLow = 1.0 + testThresholdHigh = 10.9 + testDisableHealthStatusReporting = true ) func TestExpandNrqlAlertConditionInput(t *testing.T) { @@ -714,17 +715,19 @@ func TestExpandNrqlConditionTerm(t *testing.T) { Priority: "critical", ConditionType: "static", Term: map[string]interface{}{ - "threshold": 10.9, - "threshold_duration": 5, - "threshold_occurrences": "ALL", - "operator": "equals", + "threshold": 10.9, + "threshold_duration": 5, + "threshold_occurrences": "ALL", + "operator": "equals", + "disable_health_status_reporting": true, }, Expected: &alerts.NrqlConditionTerm{ - Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"), - Priority: alerts.NrqlConditionPriority("CRITICAL"), - Threshold: &testThresholdHigh, - ThresholdDuration: 5, - ThresholdOccurrences: "ALL", + Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"), + Priority: alerts.NrqlConditionPriority("CRITICAL"), + Threshold: &testThresholdHigh, + ThresholdDuration: 5, + ThresholdOccurrences: "ALL", + DisableHealthStatusReporting: &testDisableHealthStatusReporting, }, }, "critical explicit priority": { diff --git a/website/docs/r/nrql_alert_condition.html.markdown b/website/docs/r/nrql_alert_condition.html.markdown index 6a9d1f320..057aaab56 100644 --- a/website/docs/r/nrql_alert_condition.html.markdown +++ b/website/docs/r/nrql_alert_condition.html.markdown @@ -129,6 +129,7 @@ The `term` block supports the following arguments: - `duration` - (Optional) **DEPRECATED:** Use `threshold_duration` instead. The duration of time, in _minutes_, that the threshold must violate for in order to create an incident. Must be within 1-120 (inclusive). - `time_function` - (Optional) **DEPRECATED:** Use `threshold_occurrences` instead. The criteria for how many data points must be in violation for the specified threshold duration. Valid values are: `all` or `any`. - `prediction` - (Optional) **BETA PREVIEW: the `prediction` field is in limited release and only enabled for preview on a per-account basis.** Use `prediction` to open alerts when your static threshold is predicted to be reached in the future. The `prediction` field is only available for _static_ NRQL alert conditions. See [Prediction](#prediction) below for details. +- `disable_health_status_reporting` - (Optional) `true` or `false`. Defaults to `false` when field not included in TF config. Violations will not change system health status for this term. ~> **NOTE:** When a `critical` or `warning` block is added to this resource, using either `duration` or `threshold_duration` (one of the two) is mandatory. Both of these should not be specified.