Resource manages Grafana SLOs.
resource "grafana_slo" "test" {
name = "Terraform Testing"
description = "Terraform Description"
query {
freeform {
query = "sum(rate(apiserver_request_total{code!=\"500\"}[$__rate_interval])) / sum(rate(apiserver_request_total[$__rate_interval]))"
}
type = "freeform"
}
objectives {
value = 0.995
window = "30d"
}
destination_datasource {
uid = "grafanacloud-prom"
}
label {
key = "slo"
value = "terraform"
}
alerting {
fastburn {
annotation {
key = "name"
value = "SLO Burn Rate Very High"
}
annotation {
key = "description"
value = "Error budget is burning too fast"
}
}
slowburn {
annotation {
key = "name"
value = "SLO Burn Rate High"
}
annotation {
key = "description"
value = "Error budget is burning too fast"
}
}
}
}
resource "grafana_slo" "test" {
name = "Complex Resource - Terraform Ratio Query Example"
description = "Complex Resource - Terraform Ratio Query Description"
query {
ratio {
success_metric = "kubelet_http_requests_total{status!~\"5..\"}"
total_metric = "kubelet_http_requests_total"
group_by_labels = ["job", "instance"]
}
type = "ratio"
}
objectives {
value = 0.995
window = "30d"
}
destination_datasource {
uid = "grafanacloud-prom"
}
label {
key = "slo"
value = "terraform"
}
alerting {
fastburn {
annotation {
key = "name"
value = "SLO Burn Rate Very High"
}
annotation {
key = "description"
value = "Error budget is burning too fast"
}
label {
key = "type"
value = "slo"
}
}
slowburn {
annotation {
key = "name"
value = "SLO Burn Rate High"
}
annotation {
key = "description"
value = "Error budget is burning too fast"
}
label {
key = "type"
value = "slo"
}
}
}
}
description
(String) Description is a free-text field that can provide more context to an SLO.name
(String) Name should be a short description of your indicator. Consider names like "API Availability"objectives
(Block List, Min: 1) Over each rolling time window, the remaining error budget will be calculated, and separate alerts can be generated for each time window based on the SLO burn rate or remaining error budget. (see below for nested schema)query
(Block List, Min: 1) Query describes the indicator that will be measured against the objective. Freeform Query types are currently supported. (see below for nested schema)alerting
(Block List, Max: 1) Configures the alerting rules that will be generated for each
time window associated with the SLO. Grafana SLOs can generate
alerts when the short-term error budget burn is very high, the
long-term error budget burn rate is high, or when the remaining
error budget is below a certain threshold. Annotations and Labels support templating. (see below for nested schema)destination_datasource
(Block List, Max: 1) Destination Datasource sets the datasource defined for an SLO (see below for nested schema)label
(Block List) Additional labels that will be attached to all metrics generated from the query. These labels are useful for grouping SLOs in dashboard views that you create by hand. Labels must adhere to Prometheus label name schema - "^[a-zA-Z_][a-zA-Z0-9_]*$" (see below for nested schema)id
(String) The ID of this resource.objectives
Required:
value
(Number) Value between 0 and 1. If the value of the query is above the objective, the SLO is met.window
(String) A Prometheus-parsable time duration string like 24h, 60m. This is the time window the objective is measured over.query
Required:
type
(String) Query type must be one of: "freeform", "query", "ratio", or "threshold"Optional:
freeform
(Block List, Max: 1) (see below for nested schema)ratio
(Block List, Max: 1) (see below for nested schema)query.freeform
Required:
query
(String) Freeform Query Fieldquery.ratio
Required:
success_metric
(String) Counter metric for success events (numerator)total_metric
(String) Metric for total events (denominator)Optional:
group_by_labels
(List of String) Defines Group By Labels used for per-label alerting. These appear as variables on SLO dashboards to enable filtering and aggregation. Labels must adhere to Prometheus label name schema - "^[a-zA-Z_][a-zA-Z0-9_]*$"alerting
Optional:
annotation
(Block List) Annotations will be attached to all alerts generated by any of these rules. (see below for nested schema)fastburn
(Block List, Max: 1) Alerting Rules generated for Fast Burn alerts (see below for nested schema)label
(Block List) Labels will be attached to all alerts generated by any of these rules. (see below for nested schema)slowburn
(Block List, Max: 1) Alerting Rules generated for Slow Burn alerts (see below for nested schema)alerting.annotation
Required:
key
(String)value
(String)alerting.fastburn
Optional:
annotation
(Block List) Annotations to attach only to Fast Burn alerts. (see below for nested schema)label
(Block List) Labels to attach only to Fast Burn alerts. (see below for nested schema)alerting.fastburn.annotation
Required:
key
(String)value
(String)alerting.fastburn.label
Required:
key
(String)value
(String)alerting.label
Required:
key
(String)value
(String)alerting.slowburn
Optional:
annotation
(Block List) Annotations to attach only to Slow Burn alerts. (see below for nested schema)label
(Block List) Labels to attach only to Slow Burn alerts. (see below for nested schema)alerting.slowburn.annotation
Required:
key
(String)value
(String)alerting.slowburn.label
Required:
key
(String)value
(String)destination_datasource
Optional:
uid
(String) UID for the Mimir Datasourcelabel
Required:
key
(String)value
(String)Import is supported using the following syntax:
terraform import grafana_slo.name "{{ uuid }}"