newrelic-cli icon indicating copy to clipboard operation
newrelic-cli copied to clipboard

utils/terraform: support the newrelic_one_dashboard.filter_current_dashboard attribute

Open QuentinBrosse opened this issue 2 years ago • 2 comments

Description

The newrelic_one_dashboard Terraform resource has a filter_current_dashboard attribute in some widgets blocks. These attributes are not generated with the newrelic utils terraform dashboard command.

Go Version

go version go1.17.2 darwin/amd64

Current behavior

Given a widget with the Filter the current dashboard checked:

"..."
{
  "title": "Filter By Cluster",
  "layout": {},
  "linkedEntityGuids": ["MTIzNDU2N3xWSVp8REFTSEJPQVJEfDE1NDgwCg"],
  "visualization": {"id": "viz.bar"},
  "rawConfiguration": {}
}
"..."

The current output of cat dashboard.json | newrelic utils terraform dashboard --label XXX is:

resource "newrelic_one_dashboard" "XXX" {
  # ...

  page {
    # ...

    widget_bar {
      title  = "Filter By Cluster"
       # ...

      nrql_query { /* ... */ }
    }
  }
}

Expected behavior

Given a widget with the Filter the current dashboard checked (it's the same JSON as above):

"..."
{
  "title": "Filter By Cluster",
  "layout": {},
  "linkedEntityGuids": ["MTIzNDU2N3xWSVp8REFTSEJPQVJEfDE1NDgwCg"],
  "visualization": {"id": "viz.bar"},
  "rawConfiguration": {}
}
"..."

(Maybe we should have a filterCurrentDashboard attribute in the above JSON.)

The current output of cat dashboard.json | newrelic utils terraform dashboard --label XXX is:

resource "newrelic_one_dashboard" "XXX" {
  # ...

  page {
    # ...

    widget_bar {
      title  = "Filter By Cluster"
      filter_current_dashboard = true  // <----
       # ...

      nrql_query { /* ... */ }
    }
  }
}

Steps To Reproduce

See above.

Additional Context

My first idea was to add a new line here to support this attribute. It seems not possible in the current state as the JSON representation of a dashboard (copy JSON to clipboard button) doesn't contain a filterCurrentDashboard, we only have a linkedEntityGuids.

The linkedEntityGuids seem to be a base 64 encoded string containing <account_id>|VIZ|DASHBOARD|<dashboard_id>. Here is an example:

$ echo "MTIzNDU2N3xWSVp8REFTSEJPQVJEfDE1NDgwCg" | base64 -d
1234567|VIZ|DASHBOARD|15480

I suppose the 15480 is the idea of my current dashboard. Do you use the linkedEntityGuids field to represent the Filter the current dashboard and the Filter a related dashboard features?

I'm not sure of the best way to generate the filter_current_dashboard with this JSON representation. I will welcome a bit of help. :)

References or Related Issues

N/A

QuentinBrosse avatar Apr 20 '22 14:04 QuentinBrosse

filterCurrentDashboard is a bit of a special one, as it only exists on the Terraform side. To filter the current dashboard you need the current dashboard UUID, but you don't have that when creating a new dashboard, which caused problems for our customers to use it with Terraform. Create dashboard -> Get UUID -> Update dashboard. For this reason we added it as a workaround, so we handle the complexity for our users.

This is a tough one to solve for the conversion because the exported dashboard does not contain the UUID. If it did you could compare the UUID in linkedEntityGuids with the dashboard UUID, and if they match set the filter_current_dashboard to true. I've been thinking about adding a dashboard export command to the CLI, that could include the UUID for this specific use-case, OR we could add a new parameter to newrelic utils terraform dashboard called --fromUuid to get the dashboard for us, removing the UI step.

Let me know what you think.

kidk avatar Apr 22 '22 11:04 kidk

Hi @kidk,

Thanks for explaining the context!

I'm not sure to fully understand the dashboard export command, but the --fromUuid seems to be the simpler approach. Maybe with a more explicit name (e.g. --fromDashboardUuid)?

Is adding the dashboard ID (or directly a filterCurrentDashboard field) in the exported JSON not realistic? It requires updating the NewRelic product – which could be a long process.

QuentinBrosse avatar Apr 22 '22 14:04 QuentinBrosse

Hi @QuentinBrosse, I see this issue was closed as completed. Was it addressed in some way, or was the issue closed as stale? I would love to see this problem solved.

kamilk avatar May 23 '24 14:05 kamilk