Inappropriate value for attribute "entities": a number is required. New Relic 2.1.1

Having trouble with APM Alerts in 2.1.1 against terraform 0.12.26.

Formatted code for this looks like:

resource "newrelic_alert_condition" "apdex_low" {

  policy_id       = newrelic_alert_policy.policy.id
  name            = "Apdex (Low) "
  type            = "apm_app_metric"
  entities        = [data.newrelic_entity.app.id]
  metric          = "apdex"
  runbook_url     = "https://www.example.com"
  condition_scope = "application"

  term {
    duration      = 5
    operator      = "below"
    priority      = "critical"
    threshold     = "0.9"
    time_function = "all"
  }

}

The error that appears for this is:

Error: Incorrect attribute value type

  on service-template/apm-alert.tf line 17, in resource "newrelic_alert_condition" "apdex_low":
  17:   entities        = [data.newrelic_entity.app.id]
    |----------------
    | data.newrelic_entity.app.id is "XXXXX"

Inappropriate value for attribute "entities": a number is required.

Also the documentation gets the data from the newrelic_entity but the template alert references the newrelic_application: https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/data-sources/entity

Hi, thank you for reporting the issue. Perhaps here there is an update to the documenataion that is needed. I’m able to get this working with the following reference:

data “newrelic_application” “app” {
name = “Dummy App”
}

resource “newrelic_alert_condition” “apdex_low” {

policy_id = newrelic_alert_policy.z.id
name = "Apdex (Low) "
type = “apm_app_metric”
entities = [data.newrelic_application.app.id]
metric = “apdex”
runbook_url = “https://www.example.com
condition_scope = “application”

term {
duration = 5
operator = “below”
priority = “critical”
threshold = “0.9”
time_function = “all”
}
}

The term entities on the newrelic_alert_condition resource looks to be a bad choice of words, but I see that its also referring to the newrelic_application data source and not the newrelic_entity data source. If you make those adjustments to your HCL, does it also work for you?

it looks like that works well, thanks! the warning from terraform is a bit misleading though as its instructing to use entity as well:

Warning: Use the `newrelic_entity` data source instead.

  on service-template/alert-apm.tf line 1, in data "newrelic_application" "app":
   1: data "newrelic_application" "app" {
1 Like