- Documentation
- Learning Hub
- Deploy Grafana resources as Code with Terraform
- Grafana resources and Terraform
Alerting pipeline in Terraform
How the alerting pipeline works
The notification policy tree starts with a default route. All alerts enter at the top and flow down through nested policies until they match. The first matching policy determines which contact point receives the notification.
Labels on the alert rule, like severity = "warning", are what the notification policy matches against. This is why consistent labeling matters: it’s the contract between your alert rules and your notification routing.
Example: a Slack contact point
A contact point defines a notification destination. This example sends alerts to a Slack channel.
resource "grafana_contact_point" "slack_alerts" {
name = "Slack alerts"
slack {
url = var.slack_webhook_url
title = "{{ .CommonLabels.alertname }}"
text = "{{ .CommonAnnotations.description }}"
}
}Example: a notification policy
A notification policy routes alerts to contact points based on label matching. This example routes critical alerts to PagerDuty and everything else to Slack.
resource "grafana_notification_policy" "main" {
contact_point = grafana_contact_point.slack_alerts.name
group_by = ["alertname"]
policy {
matcher {
label = "severity"
match = "="
value = "critical"
}
contact_point = grafana_contact_point.pagerduty.name
}
}