grafana / terraform-provider-grafana

Terraform Grafana provider
https://www.terraform.io/docs/providers/grafana/
Mozilla Public License 2.0
420 stars 226 forks source link

[Bug]: Mute timings that are attached to an active grafana_rule_group fail to delete #1713

Closed InGaardWeTrust closed 1 month ago

InGaardWeTrust commented 1 month ago

Terraform Version

v1.3.6

Terraform Grafana Provider Version

v3.2.0

Grafana Version

grafana cloud

Affected Resource(s)

Terraform Configuration Files

resource "grafana_mute_timing" "groupname_mute_timings" {
  for_each = toset([for key, value in local.alerts : value.groupname if value.mute == true])

  name               = each.value
  disable_provenance = true
  intervals {}
}
resource "grafana_rule_group" "this" {
  for_each = { for key, value in local.alerts : key => value }

  name               = each.value.groupname
  folder_uid         = grafana_folder.this[each.value.folder].uid
  interval_seconds   = 60
  disable_provenance = try(each.value.disable_provenance, true)

  dynamic "rule" {
    for_each = each.value.alert_data

    content {
      dynamic "notification_settings" {
        for_each = [for cur in rule.value.notifiers : cur if length(rule.value.notifiers) == 1]

        content {
          contact_point = notification_settings.value.slug
          group_by      = try(rule.value.signal_grouping.label_names, [])
          mute_timings  = each.value.mute ? [each.value.groupname] : []
        }
      }
}

Expected Behavior

Deleting mute timings that are attached to a grafana_rule_group should first be removed from the rule_group and then successfully be deleted.

Actual Behavior

Trying to delete any mute_timing that is attached to a grafana_rule_group returns the error: Error: error reading mute timing with ID0:XXXXX: [DELETE /v1/provisioning/mute-timings/{name}][409] deleteMuteTimingConflict {}

Deleting mute timings that aren't attached to a grafana_rule_group is fine. Havent tested with a notification policy.

Steps to Reproduce

  1. Create a mute timing
  2. Attach it to any alert rule
  3. Attempt to delete the mute timing
  4. Fail

Important Factoids

I believed this was taken care of in this other issue, but that was specifically for mute timing tied to notification policies. Seems like either a revert (this was working a week ago), or it never worked for notification_settings within the grafana_rule_group

References

No response

julienduchesne commented 1 month ago

This is a new feature/validation that was added in Grafana two weeks ago: https://github.com/grafana/grafana/pull/90500. I will fix this in the provider 👍