DataDog / terraform-provider-datadog

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

datadog_monitor plan/apply does not fail when "message" field has unbalanced braces #1882

Open igaskin opened 1 year ago

igaskin commented 1 year ago

Terraform Version

terraform -v
Terraform v1.3.5

Affected Resource(s)

Please list the resources as a list, for example:

Expected Behavior

The provider should validate that the "message" field for balanced braces

Actual Behavior

Applying a datadog monitor with unbalanced braces in the message will apply successfully, but will not route any notifications due to unabalanced braces

In message: unbalanced braces, found an extra }

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

nkzou commented 1 year ago

Hi, could you provide an example monitor definition that triggers this issue? I tried to reproduce with

resource "datadog_monitor" "test_monitor" {
  name = "test monitor"
  type = "query alert"
  query = "avg(current_1h):(avg:example_metric{*}) > 1"
  message = "{{#is_alert}}hello{{/is_alert"

  scheduling_options {
    evaluation_window {
      hour_starts = 0
    }
  }
}

but got │ Error: error validating monitor from https://api.datadoghq.com/api/v1/monitor/validate: 400 Bad Request: {"errors":["Invalid monitor message: {{#is_alert}} is not closed"]} during plan as expected.

edit: reproduced with an extra brace. Looking into it, seems like the monitor validation endpoint doesn't error out on extra braces.

igaskin commented 1 year ago

@nkzou would it be helpful to submit a datadog zendesk ticket for this request as well? Given that this isn't necessarily a bug in the terraform-provider-datadog but in the /validate endpoint, I'm happy to move the issue to a more appropriate place.

nkzou commented 1 year ago

According to the monitor team, the unbalanced braces pass the validate endpoint because there are situations where the extra braces are expected. As such, we can't error out the terraform plan. Ideally, we'd display the same warning as the UI validation during the terraform plan phase, but the UI uses a different endpoint for monitor text validation that isn't publicly documented. As such, I think a ticket would be helpful, though instead of a bug report I think this is actually a feature request for exposing monitor text validation warnings in the API.