Terraform New Relic V2 NRQL Alerts Not Created

In transitioning to v2, NRQL alerts that work with 1.19 are failing in 2.1.1 (against terraform 0.12.26 as the docker image for 0.13 is not available yet) in the same way. (Note: this also fails the same way if Im explicit, without the for_each and each.value references). Looking at one example, it looks like the a value lookup might be parsing this differently than we might hope:

resource "newrelic_nrql_alert_condition" "process_down" {
  for_each             = var.environment == "prod" ? local.tsm_service : {}
  policy_id            = newrelic_alert_policy.highpri-policy.id
  type                 = "static"
  name                 = "${each.value} Process Down on Host"
  description          = "Alert when process down on host"
  runbook_url          = local.runbook.tsm_runbook
  enabled              = true
  value_function       = "single_value"
  violation_time_limit = "twenty_four_hours"

  nrql {
    query             = "SELECT count(service_is_down) FROM Service_Status WHERE service_identity LIKE '%${each.value}%' AND service_is_down IS FALSE FACET host, service_identity"
    evaluation_offset = 3
  }

  critical {
    operator              = "equal"
    threshold             = 0
    threshold_duration    = 3600
    threshold_occurrences = "ALL"
  }

}

And they all fail similarly where:

Error: Argument "condition" has invalid value $condition.
In field "violationTimeLimit": Expected type "AlertsViolationTimeLimit!", found null.
In field "terms": Expected type "[AlertsNrqlConditionTermsInput!]!", found [{operator: "EQUAL", priority: "CRITICAL", thresholdDuration: 300, thresholdOccurrences: "ALL"}].
In element #1: Expected type "AlertsNrqlConditionTermsInput", found {operator: "EQUAL", priority: "CRITICAL", thresholdDuration: 300, thresholdOccurrences: "ALL"}.
In field "threshold": Expected type "Float!", found null.
In field "operator": Expected type "AlertsNrqlConditionTermsOperator!", found "EQUAL"., null

Hi Mmalave,

Thanks for reporting the issue. The threshold message I believe needs to be non-zero, but the operator has a bug in it currently, which I hope to have a release out for today. The new operator will be “equals”, not “equal”.

Also see here:



Let me know if you have any additional questions.

@mmalave, We’re also working on loosening restrictions to allow non-zero threshold values:

These fixes will make their way into the next release of the provider.

For my clarity, in current state I wont be able to use an operator of “equal” with a threshold of 0 but 2.1.3 I will only able to change the operator to “equals” with the threshold 0 for this to function?

Currently you could adjust the resource to include a “below” operator with a threshold of 0.001 or some such, which would get you close to what you are after. The next release should address both of these issues.

2 Likes

That worked great thanks!

I have very similar issue but with the above operator:

resource "newrelic_nrql_alert_condition" "restart_count" {
  policy_id            = newrelic_alert_policy.newskit_api_policy.id
  name                 = "${var.prefix} Container Restarts (${var.environment})"
  enabled              = "true"
  violation_time_limit = "TWENTY_FOUR_HOURS"
  value_function       = "single_value"
  nrql {
    query             = "SELECT uniqueCount(containerID) from K8sContainerSample WHERE namespace = '${var.namespace}' AND restartCount > 5"
    evaluation_offset = 3
  }
  # critical if any containers exceed 5 restarts
  critical {
    operator              = "above"
    threshold             = 0
    threshold_duration    = 120
    threshold_occurrences = "all"
  }
}

Error: Argument "condition" has invalid value $condition.
 
In field "terms": Expected type "[AlertsNrqlConditionTermsInput!]!", found [{operator: "ABOVE", priority: "CRITICAL", thresholdDuration: 120, thresholdOccurrences: "ALL"}].
 
In element #1: Expected type "AlertsNrqlConditionTermsInput", found {operator: "ABOVE", priority: "CRITICAL", thresholdDuration: 120, thresholdOccurrences: "ALL"}.
 
In field "threshold": Expected type "Float!", found null., null

Would changing to 0.001 work for me as well?

P.S Confirm that changing to 0.001 worked for me as well. Do you plan to fix this as well?

Hello,

Recently I’ve got a weird error message as well which goes something like this,

Error: Argument “condition” has invalid value $condition.
In field “signal”: Expected type “AlertsNrqlConditionSignalInput”, found {fillOption: “”, fillValue: null}.
In field “fillOption”: Expected type “AlertsFillOption”, found “”., null

I did check the NRQL query in the console and it works well but when in terraform with v2 provider, it doesn’t.