From 3bacb448e960f8c56905e7012311953e920310e9 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Wed, 13 Dec 2023 10:00:17 -0800 Subject: [PATCH] Fix the out of boundary error (#9628) --- .../resource_monitoring_dashboard.go | 2 +- .../resource_monitoring_dashboard_test.go | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard.go b/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard.go index 458b5cfbb1c8..0da5fbbac8b1 100644 --- a/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard.go +++ b/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard.go @@ -31,7 +31,7 @@ func removeComputedKeys(old map[string]interface{}, new map[string]interface{}) if reflect.ValueOf(v).Kind() == reflect.Slice { for i, j := range v.([]interface{}) { - if reflect.ValueOf(j).Kind() == reflect.Map { + if reflect.ValueOf(j).Kind() == reflect.Map && len(new[k].([]interface{})) > i { old[k].([]interface{})[i] = removeComputedKeys(j.(map[string]interface{}), new[k].([]interface{})[i].(map[string]interface{})) } } diff --git a/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard_test.go b/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard_test.go index 5c1a5d28afd7..0729ce06c1ed 100644 --- a/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard_test.go +++ b/mmv1/third_party/terraform/services/monitoring/resource_monitoring_dashboard_test.go @@ -117,6 +117,15 @@ func TestAccMonitoringDashboard_update(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"project"}, }, + { + Config: testAccMonitoringDashboard_gridLayoutUpdate(), + }, + { + ResourceName: "google_monitoring_dashboard.dashboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project"}, + }, }, }) } @@ -242,6 +251,52 @@ EOF `) } +func testAccMonitoringDashboard_gridLayoutUpdate() string { + return fmt.Sprintf(` +resource "google_monitoring_dashboard" "dashboard" { + dashboard_json = <