Skip to content
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

[datadog_monitor] Handle zero-based priority values #2455

Merged
merged 9 commits into from
Jul 10, 2024
21 changes: 17 additions & 4 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func resourceDatadogMonitor() *schema.Resource {
},
"priority": {
Description: "Integer from 1 (high) to 5 (low) indicating alert severity.",
nkzou marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeInt,
Type: schema.TypeString,
Optional: true,
nkzou marked this conversation as resolved.
Show resolved Hide resolved
},

Expand Down Expand Up @@ -763,17 +763,24 @@ func buildMonitorStruct(d utils.Resource) (*datadogV1.Monitor, *datadogV1.Monito
m := datadogV1.NewMonitor(d.Get("query").(string), monitorType)
m.SetName(d.Get("name").(string))
m.SetMessage(d.Get("message").(string))
m.SetPriority(int64(d.Get("priority").(int)))
m.SetOptions(o)

u := datadogV1.NewMonitorUpdateRequest()
u.SetType(monitorType)
u.SetQuery(d.Get("query").(string))
u.SetName(d.Get("name").(string))
u.SetMessage(d.Get("message").(string))
u.SetPriority(int64(d.Get("priority").(int)))
u.SetOptions(o)

if attr, ok := d.GetOk("priority"); ok {
x, _ := strconv.ParseInt(attr.(string), 10, 64)
m.SetPriority(x)
u.SetPriority(x)
} else {
m.SetPriorityNil()
u.SetPriorityNil()
}

var roles []string
if attr, ok := d.GetOk("restricted_roles"); ok {
for _, r := range attr.(*schema.Set).List() {
Expand Down Expand Up @@ -972,7 +979,13 @@ func updateMonitorState(d *schema.ResourceData, meta interface{}, m *datadogV1.M
if err := d.Set("type", m.GetType()); err != nil {
return diag.FromErr(err)
}
if err := d.Set("priority", m.GetPriority()); err != nil {

priorityStr := ""
priority, _ := m.GetPriorityOk()
if priority != nil {
priorityStr = strconv.FormatInt(*priority, 10)
}
if err := d.Set("priority", priorityStr); err != nil {
return diag.FromErr(err)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-06-16T12:02:14.869121-04:00
2024-07-03T14:24:05.861393-04:00
Loading
Loading