From f5adcc63207cea593dfb7cb1e10a27e23134e285 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Tue, 17 Jun 2025 18:06:06 +0530 Subject: [PATCH] fix: fix billboards dashboards --- newrelic/resource_newrelic_one_dashboard.go | 84 +++++++++++++++++++ newrelic/structures_newrelic_one_dashboard.go | 39 ++++++++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/newrelic/resource_newrelic_one_dashboard.go b/newrelic/resource_newrelic_one_dashboard.go index a78248e31..9e51acda4 100644 --- a/newrelic/resource_newrelic_one_dashboard.go +++ b/newrelic/resource_newrelic_one_dashboard.go @@ -566,12 +566,96 @@ func dashboardWidgetBillboardSchemaElem() *schema.Resource { Optional: true, Description: "The warning threshold value.", } + s["billboard_settings"] = &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MinItems: 1, + Elem: dashboardBillBoardWidgetSchema(), + } return &schema.Resource{ Schema: s, } } +func dashboardBillBoardWidgetSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "visual_style": { + Type: schema.TypeList, + Required: true, + Description: "Visual style settings for the billboard widget.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "display": { + Type: schema.TypeString, + Required: true, + Description: "Display mode for the visual style.", + ValidateFunc: validation.StringInSlice([]string{"auto", "all", "value", "label", "none"}, false), + }, + "alignment": { + Type: schema.TypeString, + Required: true, + Description: "Alignment for the visual style.", + ValidateFunc: validation.StringInSlice([]string{"stacked", "inline"}, false), + }, + }, + }, + }, + "grid_options": { + Type: schema.TypeList, + Required: true, + Description: "Grid options for the billboard widget.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "value": { + Type: schema.TypeInt, + Required: true, + Description: "Value size for the grid options.", + ValidateFunc: validation.IntBetween(8, 240), + }, + "label": { + Type: schema.TypeInt, + Required: true, + Description: "Label size for the grid options.", + ValidateFunc: validation.IntBetween(8, 240), + }, + "columns": { + Type: schema.TypeInt, + Required: true, + Description: "Number of columns for the grid options.", + }, + }, + }, + }, + "link": { + Type: schema.TypeList, + Optional: true, + Description: "Link settings for the billboard widget.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "title": { + Type: schema.TypeString, + Required: true, + Description: "Title for the link.", + }, + "url": { + Type: schema.TypeString, + Required: true, + Description: "URL for the link.", + }, + "new_tab": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether the link should open in a new tab.", + }, + }, + }, + }, + }, + } +} + func dashboardWidgetBulletSchemaElem() *schema.Resource { s := dashboardWidgetSchemaBase() diff --git a/newrelic/structures_newrelic_one_dashboard.go b/newrelic/structures_newrelic_one_dashboard.go index f97c85e9d..86d4ea2ea 100644 --- a/newrelic/structures_newrelic_one_dashboard.go +++ b/newrelic/structures_newrelic_one_dashboard.go @@ -246,6 +246,9 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta // Set data formatting rawConfiguration.DataFormat = expandDashboardTableWidgetConfigDataFormatInput(v.(map[string]interface{})) + // BillBoard setting + rawConfiguration.BillboardSettings = expandDashboardBillBoardWidgetSettingsInput(v.(map[string]interface{})) + widget.RawConfiguration, err = json.Marshal(rawConfiguration) if err != nil { return nil, err @@ -608,6 +611,41 @@ func expandDashboardTableWidgetConfigDataFormatInput(w map[string]interface{}) [ return nil } +func expandDashboardBillBoardWidgetSettingsInput(input map[string]interface{}) *dashboards.DashboardWidgetBillboardSettings { + if input == nil { + return nil + } + + settings := &dashboards.DashboardWidgetBillboardSettings{} + + // Expand visual_style settings + if visualStyle, ok := input["visual_style"].(map[string]interface{}); ok { + settings.Visual = &dashboards.DashboardWidgetBillboardVisual{ + Display: dashboards.BillboardVisualDisplay(visualStyle["display"].(string)), + Alignment: dashboards.BillboardVisualAlignment(visualStyle["alignment"].(string)), + } + } + + // Expand grid_options settings + if gridOptions, ok := input["grid_options"].(map[string]interface{}); ok { + settings.GridOptions = &dashboards.DashboardWidgetBillboardGridOptions{ + Columns: gridOptions["columns"].(int), + Label: gridOptions["label"].(int), + Value: gridOptions["value"].(int), + } + } + + // Expand link settings + if link, ok := input["link"].(map[string]interface{}); ok { + settings.Link = &dashboards.DashboardWidgetBillboardLink{ + Title: link["title"].(string), + URL: link["url"].(string), + NewTab: link["new_tab"].(bool), + } + } + + return settings +} func expandDashboardTableWidgetConfigurationThresholdInput(d *schema.ResourceData, pageIndex int, widgetIndex int) []dashboards.DashboardTableWidgetThresholdInput { // initialize an object of []DashboardTableWidgetThresholdInput, which would include a list of tableWidgetThresholdsToBeAdded as specified // in the Terraform configuration, with the attribute "threshold" in table widgets @@ -683,7 +721,6 @@ func expandDashboardWidgetInput(w map[string]interface{}, meta interface{}, visu if i, ok := w["title"]; ok { widget.Title = i.(string) } - if i, ok := w["linked_entity_guids"]; ok { widget.LinkedEntityGUIDs = expandLinkedEntityGUIDs(i.([]interface{})) }