terraform-provider-grafana icon indicating copy to clipboard operation
terraform-provider-grafana copied to clipboard

Inheriting contact point in nested grafana_notification_policy is not possible

Open nekater2 opened this issue 2 years ago • 3 comments

Terraform Version

  • Terraform: 1.5.4
  • Terraform Grafana Provider: 2.2.0
  • Grafana: 10.0.3

Affected Resource(s)

Please list the resources as a list, for example:

  • grafana_notification_policy

Expected Behavior

In the Grafana Documentation it says: "To inherit a contact point from the parent policy, leave it blank"

This is possible in the Grafana UI: image

And also via the Grafana API because the receiver is not required: https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#span-idroutespan-route

So I expected that either the parameter in terraform is optional or that I am able to set an empty string or null as a value to inherit the contact point from the parent.

Actual Behavior

The contact_point parameter is required as stated in the Terraform Documentation

And "leaving it blank" does also not work:

Error: status: 400, body: {"message":"invalid object specification: receiver '' does not exist","traceID":""}

      with grafana_notification_policy.self,
      on alertings.tf line 50, in resource "grafana_notification_policy" "self":
      50: resource "grafana_notification_policy" "self" {

Steps to Reproduce

resource "grafana_notification_policy" "self" {
 contact_point = "grafana-default-email"
 group_by = []
 policy {
   contact_point = ""
   group_by = []
   matcher {
     label = "test"
     match = "="
     value = "test"
   }
 }

nekater2 avatar Aug 17 '23 13:08 nekater2

Looks like a change is needed on the API side. This is what I get:

{
	"message": "invalid object specification: receiver '' does not exist",
	"traceID": ""
}

julienduchesne avatar Oct 24 '23 01:10 julienduchesne

Hi, I have the same problem when provisioning policies after manually creating them in the UI and exporting. Grafana:10.1.5

The problem is when a parent policy does not have a contact point set up, here the devops specifies the team and contact points are set up based on severity in child policies.

    policies:
    - orgId: 1
      receiver: "grafana-default-email"
      group_by:
        - grafana_folder
        - alertname
      routes:
        - object_matchers:
            - - team
              - =
              - devops
          routes:
            - receiver: "BetterUptime DevOps High"
              object_matchers:
                - - severity
                  - =
                  - high
            - receiver: "BetterUptime DevOps Low"
              object_matchers:
                - - severity
                  - =
                  - low-nightpause

PetrPhilipp avatar Dec 12 '23 10:12 PetrPhilipp

Submitted a PR to fix this in Grafana: https://github.com/grafana/grafana/pull/82007

julienduchesne avatar Feb 06 '24 18:02 julienduchesne