From d42937c3ea75371c350ba43057a3f801d7065cc0 Mon Sep 17 00:00:00 2001 From: Yurii Kyrychynskyi Date: Thu, 11 Jun 2020 18:43:57 +0200 Subject: [PATCH] Add monitor force_delete parameter --- datadog/resource_datadog_monitor.go | 17 ++++++++++++++--- website/docs/r/monitor.html.markdown | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/datadog/resource_datadog_monitor.go b/datadog/resource_datadog_monitor.go index 25ee37e7ab..b7ace17042 100644 --- a/datadog/resource_datadog_monitor.go +++ b/datadog/resource_datadog_monitor.go @@ -191,6 +191,10 @@ func resourceDatadogMonitor() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "force_delete": { + Type: schema.TypeBool, + Optional: true, + }, }, } } @@ -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") } diff --git a/website/docs/r/monitor.html.markdown b/website/docs/r/monitor.html.markdown index dc008cdda2..d25bb3bc55 100644 --- a/website/docs/r/monitor.html.markdown +++ b/website/docs/r/monitor.html.markdown @@ -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.