Skip to content

Commit

Permalink
Fix the out of boundary error (#9628)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Dec 13, 2023
1 parent de7d39b commit 3bacb44
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
}
Expand Down Expand Up @@ -242,6 +251,52 @@ EOF
`)
}

func testAccMonitoringDashboard_gridLayoutUpdate() string {
return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = <<EOF
{
"displayName": "Grid Layout Example",
"gridLayout": {
"columns": "2",
"widgets": [
{
"title": "Widget 1",
"xyChart": {
"dataSets": [{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
"aggregation": {
"perSeriesAligner": "ALIGN_RATE"
}
},
"unitOverride": "1"
},
"plotType": "LINE"
}],
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
},
{
"text": {
"content": "Widget 2",
"format": "MARKDOWN"
}
}
]
}
}
EOF
}
`)
}

func testAccMonitoringDashboard_rowLayout() string {
return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
Expand Down

0 comments on commit 3bacb44

Please sign in to comment.