在新建的 New Relic Terraformed 小部件中使用模板变量。

huangapple go评论47阅读模式
英文:

Using template variables in a new relic terraformed widget

问题

我正在使用新的Relic Terraform提供程序来生成仪表板。我希望这个仪表板是动态的,它有一个包含域名列表的变量,然后这个变量在后续的查询中被使用。例如:

SELECT * FROM Span WHERE service = {{ domain }}

假设变量被标记为 "domain"

如果我使用新的Relic GUI创建它,这样做就没问题。问题出现在我尝试通过Terraform生成仪表板时。我可以创建变量并在我的仪表板上填充它,但在查询中使用变量的语法,{{ domain }} 会引发错误。

Error: query error; Invalid widget input with id 163128331: error parsing 'SELECT uniques(`client`) FROM Span WHERE `entity.name` = 'supergraph-prod' AND service = {{ domain }}', please check nrql grammar.
Cause: Invalid nrql query.

希望我只是错过了正确的语法。但是我似乎找不到与我的问题相关的示例。任何帮助都将不胜感激。

小部件的创建方式是通过将对象传递给动态小部件创建器,将值映射到它们的正确位置。这是我的对象:

{
  title       = "Consumers"
  widget_type = "widget_table"
  query       = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}"
  row         = 1
  column      = 1
}
resource "newrelic_one_dashboard" "dashboard" {
 dynamic "widget_table" {
    for_each = page.value.widget_table
    iterator = widget
    content {
      title                    = try(widget.value.title, widget.value.query)
      filter_current_dashboard = try(widget.value.filter_current_dashboard, false)
      row                      = try(widget.value.row, 0)
      column                   = try(widget.value.column, 0)
      width                    = try(widget.value.widget_width, 4)
      height                   = try(widget.value.widget_height, 3)

      nrql_query {
        query = widget.value.query
      }
    }
  }
}

谢谢 在新建的 New Relic Terraformed 小部件中使用模板变量。

英文:

So I am using the new relic terraform provider to generate a dashboard. I want this dashboard to be dynamic, it has a variable with a list of domains and then this variable is used in the subsequent queries. For example

SELECT * FROM Span WHERE service = {{ domain }}

Assuming variable is labeled as "domain"

This works fine if I create is using the new relic GUI. The issue arrises when I attempt to generate the dashboard via terraform. I can create the variable and populate it on my dashboard just fine. But the syntax around using the variable in the queries, the {{ domain }} throws an error.

Error: query error; Invalid widget input with id 163128331: error parsing 'SELECT uniques(`client`) FROM Span WHERE `entity.name` = 'supergraph-prod' AND service = {{ domain }}'', please check nrql grammar.
│ Cause: Invalid nrql query.
│
│   with module.dashboard-federation.newrelic_one_dashboard.dashboard[0],
│   on .terraform/modules/dashboard-federation/dashboard/main.tf line 2, in resource "newrelic_one_dashboard" "dashboard":
│    2: resource "newrelic_one_dashboard" "dashboard" {

Hopefully I am just missing the correct syntax. Yet I can't seem to find an example relating to my issue online. Any help would be appreciate.

The way teh widget is created is by passing an object to a dynamic widget creator that maps the values into their correct places. Here is my object:

{
      title       = "Consumers"
      widget_type = "widget_table"
      query       = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}'"
      row         = 1
      column      = 1
    },
reasource "newrelic_one_dashboard" "dashboard" {
 dynamic "widget_table" {
        for_each = page.value.widget_table
        iterator = widget
        content {
          title                    = try(widget.value.title, widget.value.query)
          filter_current_dashboard = try(widget.value.filter_current_dashboard, false)
          row                      = try(widget.value.row, 0)
          column                   = try(widget.value.column, 0)
          width                    = try(widget.value.widget_width, 4)
          height                   = try(widget.value.widget_height, 3)

          nrql_query {
            query = widget.value.query
          }
        }
      }
}

Thanks 在新建的 New Relic Terraformed 小部件中使用模板变量。

答案1

得分: 2

Variables should be fine both with this resource and the json version. In your query you have a mistake I think, there is an extra single quote right at the end that needs to be removed

query = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}'"

should instead read:

query = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}"

(note the final single quote before the closing double quote)

Also you may consider using the attribute IN ({{domain}}) syntax to better support multi-select.

英文:

Variables should be fine both with this resource and the json version. In your query you have a mistake I think, there is an extra single quote right at the end that needs to be removed

query       = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}'"

should instead read:

query       = "SELECT uniques(client) FROM Span WHERE `entity.name` = '${var.newrelic_app_name}' AND service = {{ domain }}"

(note the final single quote before the closing double quote)

Also you may consider using the attribute IN ({{domain}}) syntax to better support multi-select.

huangapple
  • 本文由 发表于 2023年7月17日 16:57:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定