I have some intricate code, some of it alluded to in a past post where I used a dynamic { }
block to build out custom widgets for the newrelic_dashboard
resource, which will soon no longer work. We are required to move to the new newrelic_one_dashboard
quite soon, because by the end of next month the newrelic_dashboard
will stop working.
Root Module
In my current code for the newrelic_dashboard
resource and building out dynamic widget { }
s, customizable and extensible in terms of how many widget { }
s you’d like, I have this code in my root module for passing in data mappings of the content I’d like for each individual widget { }
to be created by the child module in its newrelic_dashboard
(see section after this one):
# locals for passing customized/dynamic widgets data to the child module `nr_dashboard`
locals {
# mappings for multiple widgets
dynamic_widgets = [
{
title = "Requests per minute"
visualization = "billboard"
entity_ids = [data.newrelic_entity.my_application.application_id, ]
nrql = "SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName = '${var.nr_entity_name}'"
row = 1
column = 1
},
{
...
Of course, the above is passed to the child module that creates the newrelic_dashboard
via the module { }
block:
module "newrelic_dashboard" {
...
widgets = local.dynamic_widgets
....
Current Child Module which Creates the newrelic_dashboard
In the child module which creates the dashboard, I have the code for the dashboard:
resource "newrelic_dashboard" "exampledash" {
title = "New Relic Terraform Example"
filter {
event_types = [
"Transaction"
]
attributes = [
"appName",
"name"
]
}
dynamic "widget" {
for_each = var.widgets # `widgets` is passed to us from Root module locals
content {
title = widget.value.title
visualization = widget.value.visualization
....# other required values for a `widget { }`
entity_ids = try(widget.value.entity_ids, null) # `try() is used for all attributes that are optional, such as `entity_ids`
nrql = try (widget.value.nrql, null)
....
dynamic "metric" {
for_each = try(widget.value.metric.name
content {
name = widget.value.metric.name
valus = widget.value.metric.values
}
}
....
Issue with New Relic One Dashboard
The issue with the newrelic_one_dashboard
is that widget
isn’t the name of the argument anymore for using widgets. Each widget type now has it’s own custom name - prior to this the newrelic_dashboard
kind of widget { }
was defined by the widget { }
s visualization
argument - those new custom / pre-defined widget names being for example:
widget_bar
widget_billboard
-
widget_bullet
, etc
So the issue is, how do I easily convert from my old code for newrelic_dashboard
to the newrelic_one_dashboard
, given the change in how widgets are defined in the newrelic_one_dashboard
resource?
Could I perhaps try to interpolate in the child module’s current dynamic "widget { }
block and do something like have an array of widget suffixes like so:
suffixes = [ "bar", "billboard", "bullet" ]
and then have some type of surrounding iterative block for the above array - perhaps a for_each
or other? - and interpolate each of the above values one by one into the dynamic "widget" { }
block by changing said block to the below, or similar?:
dynamic "widget_${suffix}" {
.....
Just curious, but would be great if I could move my current code to the new newrelic_one_dashboard
pretty seamlessly and keep my dynamic and extensible code for widgets.
That was a lot, thanks a lot to anyone in advance who reads/assists!