Skip to content

[datadog_dashboard_json] bugfix for template_variables and notify_list #2951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions datadog/resource_datadog_dashboard_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,20 @@ func prepResource(attrMap map[string]interface{}) map[string]interface{} {
attrMap["is_read_only"] = false
}
}
// handle `notify_list` order
if notifyList, ok := attrMap["notify_list"].([]interface{}); ok {
sort.SliceStable(notifyList, func(i, j int) bool {
return notifyList[i].(string) < notifyList[j].(string)
})

// Remove null template_variables and notify_list to avoid unnecessary diffs
if templateVars, ok := attrMap["template_variables"]; ok && templateVars == nil {
delete(attrMap, "template_variables")
}
if notifyList, ok := attrMap["notify_list"]; ok {
if notifyList == nil {
delete(attrMap, "notify_list")
} else if notifyListSlice, ok := notifyList.([]interface{}); ok {
// handle `notify_list` order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This should only be done if notifyList is defined.

sort.SliceStable(notifyListSlice, func(i, j int) bool {
return notifyListSlice[i].(string) < notifyListSlice[j].(string)
})
}
}

return attrMap
Expand Down
Loading