terraform-provider-newrelic: Data source for newrelic_entity returning incorrect ID

Terraform Version

Terraform v0.12.29

  • provider.newrelic v2.13.5

Affected Resource(s)

Please list the resources as a list, for example:

  • newrelic_alert_condition

Terraform Configuration

Please include your provider configuration (sensitive details redacted) as well as the configuration of the resources and/or data sources related to the bug report.

terraform {
  required_version = "= 0.12.29"
}

provider "newrelic" {
  account_id    = var.account_id
  admin_api_key = var.admin_api_key
  api_key       = var.api_key
  region        = var.region
  version       = "= 2.13.5"
}

data "newrelic_entity" "service1" {
  name = "Service 1"
}

data "newrelic_entity" "service2" {
  name = "Service 2"
}

resource "newrelic_alert_condition" "apdex_critical_service_apps" {
  condition_scope = "application"

  entities = [
    data.newrelic_entity.service1_id,
    data.newrelic_entity.service2_id
  ]

  metric = "apdex"
  name   = "Service Apdex (Low) - Critical"

  policy_id = data.newrelic_alert_policy.foo.id

  term {
    duration      = 10
    operator      = "below"
    priority      = "critical"
    threshold     = "0.5"
    time_function = "all"
  }

  type = "apm_app_metric"
}

Actual Behavior

The data source for data.newrelic_entity.service2_id is returning an incorrect ID. service1 works OK

Error: 422 response returned: Invalid entity id(s): 123456790.

Expected Behavior

All data sources should return the correct ID.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform plan # shows drift for the ID in the entiries
  3. terraform apply # shows the error above

Important Factoids

I suspect this is account specific and will be difficult to reproduce without access to our account. Also, this problem is not see when using the older data source for newrelic_application. Upgrading to use newrelic_application caused this issue.

We changed the data source because of this warning:

Warning: Use the `newrelic_entity` data source instead.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example: Could not find anything

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

@ctrombley thank you! Specifying the accountID via the tag in the data source does indeed work-around the issue. Looking forward to the official fix.

@pickgr I made a mistake here, it looks like we don’t have account_id plumbed in as a search parameter like I thought we did. It’s just a computed attribute. However, what you can do is use the automatic accountId entity tag in your data source config:

data "newrelic_application" "firestorm_service_prod_useast" {
  name = "Firestorm Service - Prod - IBM - USEast"
  tag {
    key = "accountId"
    value = "${var.account_id}"
  }
}

Let us know if this works!