newrelic / newrelic-cli

The New Relic Command Line Interface
https://developer.newrelic.com/explore-docs/newrelic-cli
Apache License 2.0
127 stars 73 forks source link

While converting JSON to TF resource account_id gets ignored in widget query #1567

Open TripathyC opened 7 months ago

TripathyC commented 7 months ago

Description

I am trying to convert some of my dashboards created manually to Terraform. For which I am using the steps provided in https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/resources/one_dashboard#use-the-new-relic-cli-to-convert-an-existing-dashboard There was no mention here on how to export the terraform into a file but I figured that out by adding -o file.tfto the command & it did the work.

Go Version

I dont use Go.

Current behavior

When I tried to use the newrelic cli to convert my dashboard.json to a Terraform resource, the account_id gets ignored & not present in the widgets. It comes like this.

nrql_query {
        query = <<EOT
query
EOT
      }

Expected behavior

The block nrql_query should also have the account_id associated with that query. Like this

nrql_query {
        account_id = ***
        query = <<EOT
query
EOT
      }

Steps To Reproduce

Steps to reproduce the behavior:

  1. Export any dashboard & save as Json file, lets say file is dashboard.json. And make sure you are in a multi account Newrelic organization account where your query needs to be ran on a specific account.
  2. Make sure to install newrelic cli :)
  3. Then run cat dashboard.json | newrelic utils terraform dashboard --label my_dashboard_resource -o dashboard.tf
  4. Check in the newly created dashboard.tf file & you will see no account_id attribute is present inside nrql_query block.

References or Related Issues

https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/resources/one_dashboard#use-the-new-relic-cli-to-convert-an-existing-dashboard

TripathyC commented 7 months ago

To add more, this is what I have in my JSON inside the nrqlQueries block "nrqlQueries": [ { "accountIds": [ ** ], "query": "**" } ]