Skip to content

Commit

Permalink
explicitly silent a monitor when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Nov 27, 2018
1 parent 6f35249 commit 17eea5f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,15 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
if attr, ok := d.GetOk("escalation_message"); ok {
o.SetEscalationMessage(attr.(string))
}
silenced := false
if attr, ok := d.GetOk("silenced"); ok {
// TODO: this is not very defensive, test if we can fail non int input
s := make(map[string]int)
for k, v := range attr.(map[string]interface{}) {
s[k] = v.(int)
}
o.Silenced = s
silenced = true
}
if attr, ok := d.GetOk("locked"); ok {
o.SetLocked(attr.(bool))
Expand All @@ -426,7 +428,19 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("error updating monitor: %s", err.Error())
}

return resourceDatadogMonitorRead(d, meta)
var retval error
if retval = resourceDatadogMonitorRead(d, meta); retval != nil {
return retval
}

if _, ok := d.GetOk("silenced"); ok && !silenced {
// This means the monitor must be manually unmuted since the API
// wouldn't do it automatically when `silenced` is just missing
retval = client.UnmuteMonitor(*m.Id)
d.Set("silenced", nil)
}

return retval
}

func resourceDatadogMonitorDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down

0 comments on commit 17eea5f

Please sign in to comment.