Skip to content

Commit

Permalink
Merge pull request #535 from ykyr/monitor-force-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
gzussa authored Jun 19, 2020
2 parents c642976 + d42937c commit 8e228b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func resourceDatadogMonitor() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"force_delete": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -554,14 +558,21 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro

func resourceDatadogMonitorDelete(d *schema.ResourceData, meta interface{}) error {
providerConf := meta.(*ProviderConfiguration)
client := providerConf.CommunityClient
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

i, err := strconv.Atoi(d.Id())
i, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return err
}

if err = client.DeleteMonitor(i); err != nil {
if d.Get("force_delete").(bool) {
_, _, err = datadogClientV1.MonitorsApi.DeleteMonitor(authV1, i).Force("true").Execute()
} else {
_, _, err = datadogClientV1.MonitorsApi.DeleteMonitor(authV1, i).Execute()
}

if err != nil {
return translateClientError(err, "error deleting monitor")
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/monitor.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The following arguments are supported:
Default: True for "on average", "at all times" and "in total" aggregation. False otherwise.
* `locked` (Optional) A boolean indicating whether changes to to this monitor should be restricted to the creator or admins. Defaults to False.
* `tags` (Optional) A list of tags to associate with your monitor. This can help you categorize and filter monitors in the manage monitors page of the UI. Note: it's not currently possible to filter by these tags when querying via the API
* `force_delete` (Optional) A boolean indicating whether this monitor can be deleted even if it’s referenced by other resources (e.g. SLO, composite monitor).
* `threshold_windows` (Optional) A mapping containing `recovery_window` and `trigger_window` values, e.g. `last_15m`. Can only be used for, and are required for, anomaly monitors.
* `recovery_window` describes how long an anomalous metric must be normal before the alert recovers.
* `trigger_window` describes how long a metric must be anomalous before an alert triggers.
Expand Down

0 comments on commit 8e228b0

Please sign in to comment.