Manages Grafana Alerting rule groups.
This resource requires Grafana 9.1.0 or later.
resource "grafana_folder" "rule_folder" {
title = "My Alert Rule Folder"
}
resource "grafana_rule_group" "my_alert_rule" {
name = "My Rule Group"
folder_uid = grafana_folder.rule_folder.uid
interval_seconds = 240
org_id = 1
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
no_data_state = "NoData"
exec_err_state = "Alerting"
annotations = {
"a" = "b"
"c" = "d"
}
labels = {
"e" = "f"
"g" = "h"
}
is_paused = false
data {
ref_id = "A"
query_type = ""
relative_time_range {
from = 600
to = 0
}
datasource_uid = "PD8C576611E62080A"
model = jsonencode({
hide = false
intervalMs = 1000
maxDataPoints = 43200
refId = "A"
})
}
data {
ref_id = "B"
query_type = ""
relative_time_range {
from = 0
to = 0
}
datasource_uid = "-100"
model = <<EOT
{
"conditions": [
{
"evaluator": {
"params": [
3
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"A"
]
},
"reducer": {
"params": [],
"type": "last"
},
"type": "query"
}
],
"datasource": {
"type": "__expr__",
"uid": "-100"
},
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 43200,
"refId": "B",
"type": "classic_conditions"
}
EOT
}
}
}
folder_uid
(String) The UID of the folder that the group belongs to.interval_seconds
(Number) The interval, in seconds, at which all rules in the group are evaluated. If a group contains many rules, the rules are evaluated sequentially.name
(String) The name of the rule group.rule
(Block List, Min: 1) The rules within the group. (see below for nested schema)disable_provenance
(Boolean) Allow modifying the rule group from other sources than Terraform or the Grafana API. Defaults to false
.org_id
(String) The Organization ID. If not set, the Org ID defined in the provider block will be used.id
(String) The ID of this resource.rule
Required:
condition
(String) The ref_id
of the query node in the data
field to use as the alert condition.data
(Block List, Min: 1) A sequence of stages that describe the contents of the rule. (see below for nested schema)name
(String) The name of the alert rule.Optional:
annotations
(Map of String) Key-value pairs of metadata to attach to the alert rule that may add user-defined context, but cannot be used for matching, grouping, or routing. Defaults to map[]
.exec_err_state
(String) Describes what state to enter when the rule's query is invalid and the rule cannot be executed. Options are OK, Error, KeepLast, and Alerting. Defaults to Alerting
.for
(String) The amount of time for which the rule must be breached for the rule to be considered to be Firing. Before this time has elapsed, the rule is only considered to be Pending. Defaults to 0
.is_paused
(Boolean) Sets whether the alert should be paused or not. Defaults to false
.labels
(Map of String) Key-value pairs to attach to the alert rule that can be used in matching, grouping, and routing. Defaults to map[]
.no_data_state
(String) Describes what state to enter when the rule's query returns No Data. Options are OK, NoData, KeepLast, and Alerting. Defaults to NoData
.notification_settings
(Block List, Max: 1) Notification settings for the rule. If specified, it overrides the notification policies. Available since Grafana 10.4, requires feature flag 'alertingSimplifiedRouting' enabled. (see below for nested schema)Read-Only:
uid
(String) The unique identifier of the alert rule.rule.data
Required:
datasource_uid
(String) The UID of the datasource being queried, or "-100" if this stage is an expression stage.model
(String) Custom JSON data to send to the specified datasource when querying.ref_id
(String) A unique string to identify this query stage within a rule.relative_time_range
(Block List, Min: 1, Max: 1) The time range, relative to when the query is executed, across which to query. (see below for nested schema)Optional:
query_type
(String) An optional identifier for the type of query being executed. Defaults to ``.rule.data.relative_time_range
Required:
from
(Number) The number of seconds in the past, relative to when the rule is evaluated, at which the time range begins.to
(Number) The number of seconds in the past, relative to when the rule is evaluated, at which the time range ends.rule.notification_settings
Required:
contact_point
(String) The contact point to route notifications that match this rule to.Optional:
group_by
(List of String) A list of alert labels to group alerts into notifications by. Use the special label ...
to group alerts by all labels, effectively disabling grouping. If empty, no grouping is used. If specified, requires labels 'alertname' and 'grafana_folder' to be included.group_interval
(String) Minimum time interval between two notifications for the same group. Default is 5 minutes.group_wait
(String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.mute_timings
(List of String) A list of mute timing names to apply to alerts that match this policy.repeat_interval
(String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.Import is supported using the following syntax:
terraform import grafana_rule_group.name "{{ folderUID }}:{{ title }}"
terraform import grafana_rule_group.name "{{ orgID }}:{{ folderUID }}:{{ title }}"