Terraform-provider-newrelic: BUG: Unable to create NR1 dashboard via Terraform with default account_id

Created on 6 Feb 2021  Â·  6Comments  Â·  Source: newrelic/terraform-provider-newrelic

Summary

With the recent addition of newrelic_one_dashboard, I copy pasted the usage example from the provider docs. Since it's stated that account_id is optional, I removed those 2 lines. As per the docs, New Relic should default to the associated account from the API key used. Instead the following error is returned:

The argument "account_id" is required, but no definition was found.

Please note, this is different from the error whereby an account_id isn't supplied to the resource ("The argument "account_id" is required, but was not set.").

Attempts

I've cycled through my: User, Admin and REST keys, without success. I don't get why this resource needs the account_id to be set explicitly when others don't. This seems erroneous and conflicts with documentation.

What's more, in order to fetch me account_id, I need my account_id (or the account name; but who uses names as unique identifiers?). Not sure if I'm missing something obvious here.

Also raised on the forum. Thanks for your time.

Code

terraform {
  required_version = "~> 0.14.0"
  required_providers {
    newrelic = {
      source = "newrelic/newrelic"
      version = "~> 2.17.0"
    }
  }
}

provider "newrelic" {
  account_id = 123456
  api_key = "NRAK-abcdefg"
}

resource "newrelic_one_dashboard" "exampledash" {
  name = "New Relic Terraform Example"
  page {
    name = "New Relic Terraform Example"
    widget_billboard {
      title = "Requests per minute"
      row = 1
      column = 1
      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }
    }
  }
}

AC

The expected behavior would be for this to inherit from the Dashboard's account_id which is inherited from the provider block.

bug S

Most helpful comment

This should be a trivial fix since we already have a helper function for other resources. Though I believe the expected behavior would be for this to inherit from the Dashboard's account_id which is inherited from the provider block.

All 6 comments

@rdhar thanks for reporting this, we'll take a look. as a workaround can you leave the account_id in the configuration file?

Thanks for picking this up, @jpvajda.

That's right—unlike any other Terraform entity—newrelic_one_dashboard explicitly requires account_id to be declared in every single NRQL widget. This breaks the expected flow of the default account_id being passed through all other resources.

@jthurman42 any thoughts on this?

This should be a trivial fix since we already have a helper function for other resources. Though I believe the expected behavior would be for this to inherit from the Dashboard's account_id which is inherited from the provider block.

@jthurman42 I agree.

Brilliant, thanks once again for addressing this so promptly! Looking forward to seeing this being released soon 🤞

Was this page helpful?
0 / 5 - 0 ratings