From a2c0859c6ec081e3646f5acd1771b6140403d7c0 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Mon, 5 Jun 2023 09:51:38 -0400 Subject: [PATCH 1/2] Fix potential panic on dashboards Closes https://github.com/grafana/terraform-provider-grafana/issues/921 --- internal/resources/grafana/resource_dashboard.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/resources/grafana/resource_dashboard.go b/internal/resources/grafana/resource_dashboard.go index 5d543afa3..f77f7271e 100644 --- a/internal/resources/grafana/resource_dashboard.go +++ b/internal/resources/grafana/resource_dashboard.go @@ -362,7 +362,7 @@ func NormalizeDashboardConfigJSON(config interface{}) string { // from the dashboard JSON other than "name" or "uid". // Grafana will populate all other libraryPanel attributes, so delete them to avoid diff. panels, hasPanels := dashboardJSON["panels"] - if hasPanels { + if hasPanels && panels != nil { for _, panel := range panels.([]interface{}) { panelMap := panel.(map[string]interface{}) delete(panelMap, "id") From 7706524e2ecce9073e3f1a2cb0a2200d932171e2 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Tue, 6 Jun 2023 09:31:16 -0400 Subject: [PATCH 2/2] Simplify access logic --- internal/resources/grafana/resource_dashboard.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/resources/grafana/resource_dashboard.go b/internal/resources/grafana/resource_dashboard.go index f77f7271e..47054c04e 100644 --- a/internal/resources/grafana/resource_dashboard.go +++ b/internal/resources/grafana/resource_dashboard.go @@ -361,9 +361,8 @@ func NormalizeDashboardConfigJSON(config interface{}) string { // similarly to uid removal above, remove any attributes panels[].libraryPanel.* // from the dashboard JSON other than "name" or "uid". // Grafana will populate all other libraryPanel attributes, so delete them to avoid diff. - panels, hasPanels := dashboardJSON["panels"] - if hasPanels && panels != nil { - for _, panel := range panels.([]interface{}) { + if panels, ok := dashboardJSON["panels"].([]interface{}); ok { + for _, panel := range panels { panelMap := panel.(map[string]interface{}) delete(panelMap, "id") if libraryPanel, ok := panelMap["libraryPanel"].(map[string]interface{}); ok {