Terraform-provider-newrelic: newrelic_application data source: Chicken/Egg Problem retrieving application ID

Created on 29 Oct 2018  路  5Comments  路  Source: newrelic/terraform-provider-newrelic

Terraform Version

v0.11.8

Affected Resource(s)

  • newrelic_application data source
  • newrelic_alert_condition resource

Terraform Configuration Files

Consider the case where:

  • I'm configuring some infrastructure to be able to run an application (eg, an AWS ECS cluster+service)
  • I'm configuring an NewRelic alert condition, associated with that application

Let's say I'm running terraform for the first time, to configure both the application and the NewRelic alerts+conditions. I'll have some HCL like

# Configure the application
resource "aws_ecs_task_definition" "service" {
   // ...
  container_definitions = <<JSON
  {
    ...
    "environment": [{
      "name": "NEW_RELIC_APP_NAME",
      "value": "my-app"
    }]
  }
JSON
}

# Configure a New Relic alert condition
resource "newrelic_nrql_alert_condition" "some_condition" {
  // ...

  // Condition must reference Application by unique ID
  // Only way to get this ID is via a `newrelic_application` data source
  entities = ["${data.newrelic_application.my_app.id}"]
}

data "newrelic_application" "my_app" {
  name = "my-app"
}

The problem is that when I first run this terraform configuration, the application has not yet been registered in NewRelic, so the newrelic_application data source fails at terraform plan with:

Error: Error refreshing state: 1 error(s) occurred:

* data.newrelic_application.my_app: 1 error(s) occurred:

* data.newrelic_application.my_app: data.newrelic_application.my_app: The name 'my-app' does not match any New Relic applications.

I'm not sure how exactly you could work around this, but any ideas would be appreciated.

Debug Output

N/A

Panic Output

N/A

Expected Behavior

See _Terraform Configuration Files_ above

Actual Behavior

See _Terraform Configuration Files_ above

Steps to Reproduce

See _Terraform Configuration Files_ above

Important Factoids

See _Terraform Configuration Files_ above

References

Most helpful comment

The above is all correct. I will open a feature request for a REST V2 API endpoint for creating applications, as this workflow will become increasingly common. Closing this issue for now.

All 5 comments

I don't this this is an issue with the provider, I think it's an issue with how you're using it. The terraform provider checks for existing applications, if the application doesn't exist the best thing to do would be to break out the application creation into a separate terraform file or process and create it prior to trying to use the New Relic resource in one of your TF files.

I was told at one point there is no API call to create an APM app, as it requires running the app in the APM Agent.

I work for New Relic, this is currently true.

As a workaround, you can either spin up an application with the newrelic agent for whatever name you want to create and spin it back down (we have a nodejs cli tool for this) or just impersonate the agent registration APM call. The former is much easier, but definitely not as clean.

I really don't understand why New Relic doesn't have an API call to create an application, since it is possible to work around.

The above is all correct. I will open a feature request for a REST V2 API endpoint for creating applications, as this workflow will become increasingly common. Closing this issue for now.

Was this page helpful?
0 / 5 - 0 ratings