terraform-provider-newrelic: `newrelic_entity` data source doesn't find entity in sub-account

Recently I started to split organisation’s single account into client-specific sub-accounts. I found out that the current newrelic_entity data source filter doesn’t work, so I’ve added accountID tag filter to it as recommended in the doc. However, despite NewRelic API returns expected response, provider resource doesn’t accept it and returns “not found” error.

Terraform Version

$ terraform -v
Terraform v1.1.6
on darwin_arm64
+ provider registry.terraform.io/newrelic/newrelic v3.25.2

Affected Resource(s)

Terraform Configuration

data "newrelic_account" "default" {
  count = var.newrelic_enabled ? 1 : 0

  name = "Acme Inc" # sub-account
}


data "newrelic_entity" "apm" {
  count = var.newrelic_enabled ? 1 : 0

  name       = "ABC"
  type       = "APPLICATION"
  domain     = "APM"

  tag {
    key   = "accountID"
    value = data.newrelic_account.default[0].id
  }
}

Actual Behavior

│ Error: no entities found for the provided search parameters, please ensure your schema attributes are valid

Expected Behavior

The provider processes API response correctly.

Steps to Reproduce

  1. terraform apply

Debug Output

2023-07-17T17:15:41.045+0100 [INFO]  provider.terraform-provider-newrelic_v3.25.2: 2023/07/17 17:15:41 [DEBUG] newrelic API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Mon, 17 Jul 2023 16:15:40 GMT
Proxied-By: Service Gateway
Served-By: nerd-graph
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: accept-encoding
X-Envoy-Upstream-Service-Time: 303

2d9
{
 "data": {
  "actor": {
   "entitySearch": {
    "count": 1,
    "query": "name = 'ABC' AND domain = 'APM' AND type = 'APPLICATION' AND tags.`accountID` = '12345678'",
    "results": {
     "entities": [
      {
       "__typename": "ApmApplicationEntityOutline",
       "accountId": 12345678,
       "alertSeverity": "NOT_CONFIGURED",
       "applicationId": 1230940855,
       "domain": "APM",
       "entityType": "APM_APPLICATION_ENTITY",
       "guid": "NDAxOTY4NHxBUE18QVBQTElDQVRJT058MTIzMDk0MDg1NQ",
       "indexedAt": 1689609074704,
       "language": "ruby",
       "name": "ABC",
       "permalink": "https://one.newrelic.com/redirect/entity/NDAxOTY4NHxBUE18QVBQTElDQVRJT058MTIzMDk0MDg1NQ",
       "reporting": true,
       "type": "APPLICATION"
      }
     ],
     "nextCursor": null
    },
    "types": [
     {
      "count": 1,
      "domain": "APM",
      "entityType": "APM_APPLICATION_ENTITY",
      "type": "APPLICATION"
     }
    ]
   }
  }
 }
}
0


As you may note the output is expected – 1 APM entity in the response entities list. The same result can be observed by querying the same criteria within NewRelic CLI:

$ newrelic entity search --domain APM --type APPLICATION --name ABC --tag accountID:12345678
{
  "account": {},
  "accountId": 12345678,
  "alertSeverity": "NOT_CONFIGURED",
  "apmBrowserSummary": {},
  "apmSummary": {},
  "applicationId": 1230940855,
  "dashboardTemplates": null,
  "domain": "APM",
  "entityType": "APM_APPLICATION_ENTITY",
  "goldenMetrics": {
    "context": {},
    "metrics": null
  },
  "goldenSignalValues": null,
  "goldenSignalValuesV2": {
    "signalValues": null,
    "timeIndex": null
  },
  "goldenTags": {
    "context": {},
    "tags": null
  },
  "guid": "NDAxOTY4NHxBUE18QVBQTElDQVRJT058MTIzMDk0MDg1NQ",
  "indexedAt": 1689609074704,
  "language": "ruby",
  "name": "ABC",
  "permalink": "https://one.newrelic.com/redirect/entity/NDAxOTY4NHxBUE18QVBQTElDQVRJT058MTIzMDk0MDg1NQ",
  "recommendedServiceLevel": {
    "indicators": null
  },
  "relatedDashboards": {
    "dashboardGuids": null,
    "dashboards": null
  },
  "reporting": true,
  "runningAgentVersions": {},
  "serviceLevel": {
    "indicators": null
  },
  "settings": {},
  "type": "APPLICATION",
  "uiTemplates": null
}

Important Factoids

I run Terraform with USER API key created in the main (default) NewRelic organisation account (10000000), but the target entity resides in the sub-account (12345678). For some reason that works for NewRelic CLI, but not for Terraform provider (Go client returns an expected response).

References

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 19 (19 by maintainers)

Most upvoted comments

@pranav-new-relic Much obliged with this uber-fast release 🙇

v3.26.0 with this code addition is now out 😃

Cool, thanks for taking a look! I’ll continue to look into taking the PR forward tomorrow 😃

@pranav-new-relic Please take a look into PR and assist with necessary acctest changes 🙇

Yes, something like an extra data source attribute is precisely what I’m thinking of:

data "newrelic_entity" "foobar" {
  account_id = "12345678" # Many other resources already have this attribute
  ...
}

If you decide with the team it makes sense from the design point of view, I’m eager to spend my time and contribute to the code (I have some prior experience with other Terraform providers). Looking forward for your decision 🙇