-
Notifications
You must be signed in to change notification settings - Fork 2
/
dash_nrql_composed.tf
51 lines (43 loc) · 1.21 KB
/
dash_nrql_composed.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
variable NEW_RELIC_API_KEY {
type = string
}
provider "graphql" {
url = "https://api.newrelic.com/graphql"
headers = {
"API-Key" = var.NEW_RELIC_API_KEY
}
}
data "graphql_query" "basic_query" {
query_variables = {
accountId = var.accountId
}
query = file("./getTopFiveApis.gql")
}
# Uncoment to see the output from the NRQL query
# output "response" {
# value = data.graphql_query.basic_query.query_response
# }
# This generates the 'rows' of widgets from the CONFIG object
locals {
composed_render = templatefile(
"${path.module}/dashboards/nrql_composed_widgets.json.tftpl",
{
ACCOUNTID = var.accountId
CONFIG = jsondecode(data.graphql_query.basic_query.query_response).data.actor.account.nrql.results
}
)
}
resource "newrelic_one_dashboard_json" "nrql_dashboard" {
json = local.composed_render
}
#Lets tag terraform managed dashboards!
resource "newrelic_entity_tags" "nrql_dashboard" {
guid = newrelic_one_dashboard_json.nrql_dashboard.guid
tag {
key = "terraform"
values = [true]
}
}
output "nrql_dashboard" {
value=newrelic_one_dashboard_json.nrql_dashboard.permalink
}