Skip to content

Commit 861843f

Browse files
feat(dashboard): support multiple account id's when creating dashboards
1 parent 126a95b commit 861843f

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

internal/utils/terraform/dashboard.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,8 @@ func GenerateDashboardHCL(resourceLabel string, shiftWidth int, input []byte) (s
170170
h.WriteStringSliceAttributeIfNotEmpty("linked_entity_guids", config.LinkedEntityGUIDs)
171171
h.WriteMultilineStringAttributeIfNotEmpty("text", config.Text)
172172

173-
for _, q := range config.NRQLQueries {
174-
h.WriteBlock("nrql_query", []string{}, func() {
175-
parts := strings.Split(q.Query, "||SPECIAL_ACCOUNT_ID:")
176-
if len(parts) > 1 {
177-
specialAccountID := parts[1]
178-
q.Query = parts[0]
179-
h.WriteStringAttribute("account_id", specialAccountID)
180-
} else if len(q.AccountIDs) == 1 {
181-
if q.AccountIDs[0] != -1 {
182-
h.WriteIntAttribute("account_id", q.AccountIDs[0])
183-
}
184-
} else if len(q.AccountIDs) > 1 {
185-
accountIDsStr := fmt.Sprintf("[%s]", strings.Join(strings.Fields(fmt.Sprint(q.AccountIDs)), ","))
186-
h.WriteStringAttribute("account_id", accountIDsStr)
187-
}
188-
h.WriteMultilineStringAttribute("query", q.Query)
189-
})
190-
}
173+
writeNRQLQueries(h, config.NRQLQueries)
174+
191175
h.WriteBooleanAttribute("facet_show_other_series", config.Facet.ShowOtherSeries)
192176
h.WriteBooleanAttribute("legend_enabled", config.Legend.Enabled)
193177
h.WriteBooleanAttribute("ignore_time_range", config.PlatformOptions.IgnoreTimeRange)
@@ -284,6 +268,27 @@ func GenerateDashboardHCL(resourceLabel string, shiftWidth int, input []byte) (s
284268
return h.String(), nil
285269
}
286270

271+
func writeNRQLQueries(h *HCLGen, queries []DashboardWidgetNRQLQuery) {
272+
for _, q := range queries {
273+
h.WriteBlock("nrql_query", []string{}, func() {
274+
parts := strings.Split(q.Query, "||SPECIAL_ACCOUNT_ID:")
275+
if len(parts) > 1 {
276+
specialAccountID := parts[1]
277+
q.Query = parts[0]
278+
h.WriteStringAttribute("account_id", specialAccountID)
279+
} else if len(q.AccountIDs) == 1 {
280+
if q.AccountIDs[0] != -1 {
281+
h.WriteIntAttribute("account_id", q.AccountIDs[0])
282+
}
283+
} else if len(q.AccountIDs) > 1 {
284+
accountIDsStr := fmt.Sprintf("[%s]", strings.Join(strings.Fields(fmt.Sprint(q.AccountIDs)), ","))
285+
h.WriteStringAttribute("account_id", accountIDsStr)
286+
}
287+
h.WriteMultilineStringAttribute("query", q.Query)
288+
})
289+
}
290+
}
291+
287292
func unmarshalDashboardWidgetRawConfiguration(title string, widgetType string, b []byte) *DashboardWidgetRawConfiguration {
288293
var c DashboardWidgetRawConfiguration
289294
err := json.Unmarshal(b, &c)

0 commit comments

Comments
 (0)