DataDog / terraform-provider-datadog

Terraform Datadog provider
https://www.terraform.io/docs/providers/datadog/
Mozilla Public License 2.0
403 stars 378 forks source link

Composite monitors - Force recreate on dependent monitor destroy #1452

Open stobias123 opened 2 years ago

stobias123 commented 2 years ago

We've had to re-create lots of monitors after the events alert type deprecation in favor of events-v2.

Terraform Version

Terraform v1.1.6
on darwin_amd64

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "datadog_monitor" "recreated_monitor" {
  message = "foo"
  name    = "foo composite"
  type    = "events-v2"
  }

resource "datadog_monitor" "composite" {
  message = "foo"
  name    = "foo composite"
  type    = "composite"
  query   = "${datadog_monitor.recreated_monitor.id} && !${datadog_monitor.existing_monitor.id}"
  ...
  }

Expected Behavior

Since there is a dependency on datadog_monitor.recreated_monitior from datadog_monitor.composite, I expect datadog_monitor of type composite to trigger destroy/recreate when query value changes.

Actual Behavior

When changing the below recreated_monitor to events-v2, a terraform plan shows that datadog_monitior.recreated_monitor must be replaced, this is expected.

But on destroy, we get the below error.

 error deleting monitor from https://api.datadoghq.com/api/v1/monitor/386222234: 400 Bad Request: {"errors": ["defaultdict(<type 'list'>, {3863333134: [u'monitor [386433334,[Raw] Node scale down affecting foooomonitor] is referenced in composite monitors: [386333338,foooo HIGH], [3863333339,fooooo uptime]']})"]}

Steps to Reproduce

Create monitors as described above. Taint the recreated_monitor resource. Observe api failure on terraform apply

skarimo commented 2 years ago

You should be able to set force_delete on the child monitor which should allow it to recreate even if referenced in composite monitors. This might need to happen in 2 steps: 1) apply force_delete on the resource 2) update the monitor to trigger recreation. Terraform sdk seem to ignore new fields when ForceNew is triggered.