Skip to content

Commit c9b51a8

Browse files
Fix the out of boundary error (#9628) (#6750)
[upstream:3bacb448e960f8c56905e7012311953e920310e9] Signed-off-by: Modular Magician <[email protected]>
1 parent 16d58fc commit c9b51a8

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

.changelog/9628.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
monitoring: fixed the index out of range crash in `dashboard_json` perma-diffs for the resource `google_monitoring_dashboard`
3+
```

google-beta/services/monitoring/resource_monitoring_dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func removeComputedKeys(old map[string]interface{}, new map[string]interface{})
3333

3434
if reflect.ValueOf(v).Kind() == reflect.Slice {
3535
for i, j := range v.([]interface{}) {
36-
if reflect.ValueOf(j).Kind() == reflect.Map {
36+
if reflect.ValueOf(j).Kind() == reflect.Map && len(new[k].([]interface{})) > i {
3737
old[k].([]interface{})[i] = removeComputedKeys(j.(map[string]interface{}), new[k].([]interface{})[i].(map[string]interface{}))
3838
}
3939
}

google-beta/services/monitoring/resource_monitoring_dashboard_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ func TestAccMonitoringDashboard_update(t *testing.T) {
119119
ImportStateVerify: true,
120120
ImportStateVerifyIgnore: []string{"project"},
121121
},
122+
{
123+
Config: testAccMonitoringDashboard_gridLayoutUpdate(),
124+
},
125+
{
126+
ResourceName: "google_monitoring_dashboard.dashboard",
127+
ImportState: true,
128+
ImportStateVerify: true,
129+
ImportStateVerifyIgnore: []string{"project"},
130+
},
122131
},
123132
})
124133
}
@@ -244,6 +253,52 @@ EOF
244253
`)
245254
}
246255

256+
func testAccMonitoringDashboard_gridLayoutUpdate() string {
257+
return fmt.Sprintf(`
258+
resource "google_monitoring_dashboard" "dashboard" {
259+
dashboard_json = <<EOF
260+
{
261+
"displayName": "Grid Layout Example",
262+
"gridLayout": {
263+
"columns": "2",
264+
"widgets": [
265+
{
266+
"title": "Widget 1",
267+
"xyChart": {
268+
"dataSets": [{
269+
"timeSeriesQuery": {
270+
"timeSeriesFilter": {
271+
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
272+
"aggregation": {
273+
"perSeriesAligner": "ALIGN_RATE"
274+
}
275+
},
276+
"unitOverride": "1"
277+
},
278+
"plotType": "LINE"
279+
}],
280+
"timeshiftDuration": "0s",
281+
"yAxis": {
282+
"label": "y1Axis",
283+
"scale": "LINEAR"
284+
}
285+
}
286+
},
287+
{
288+
"text": {
289+
"content": "Widget 2",
290+
"format": "MARKDOWN"
291+
}
292+
}
293+
]
294+
}
295+
}
296+
297+
EOF
298+
}
299+
`)
300+
}
301+
247302
func testAccMonitoringDashboard_rowLayout() string {
248303
return fmt.Sprintf(`
249304
resource "google_monitoring_dashboard" "dashboard" {

0 commit comments

Comments
 (0)