feat: grafana IRM escalation module
All checks were successful
terraform-dev / validate (push) Successful in 7s
terraform-dev / plan (push) Successful in 7s
terraform-dev / apply (push) Has been skipped

новый модуль modules/grafana_irm_escalation, dev/adibrov подключён.
секреты (oncall_access_token, user id) хранятся в Vault, в git не попадают
This commit is contained in:
Alexandr
2026-04-01 08:21:03 +03:00
parent a9e7ad4831
commit 5d05640e80
9 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,21 @@
resource "grafana_oncall_escalation_chain" "this" {
name = var.name
team_id = var.team_id
}
resource "grafana_oncall_escalation" "steps" {
# ключ = строковый индекс; порядок шагов фиксирован через position
for_each = { for idx, step in var.steps : tostring(idx) => step }
escalation_chain_id = grafana_oncall_escalation_chain.this.id
type = each.value.type
position = tonumber(each.key)
duration = each.value.duration_seconds
persons_to_notify = each.value.persons_to_notify
persons_to_notify_next_each_time = each.value.persons_to_notify_next_each_time
notify_on_call_from_schedule = each.value.notify_on_call_from_schedule
group_to_notify = each.value.group_to_notify
action_to_trigger = each.value.action_to_trigger
notify_to_team_members = each.value.notify_to_team_members
important = each.value.important
}

View File

@ -0,0 +1,9 @@
output "escalation_chain_id" {
description = "ID цепочки эскалации — используется в grafana_oncall_route для привязки алертов"
value = grafana_oncall_escalation_chain.this.id
}
output "escalation_chain_name" {
description = "Название цепочки эскалации"
value = grafana_oncall_escalation_chain.this.name
}

View File

@ -0,0 +1,67 @@
variable "name" {
description = "Название цепочки эскалации"
type = string
}
variable "team_id" {
description = "ID команды в Grafana IRM (опционально)"
type = string
default = null
}
variable "steps" {
description = <<-EOT
Шаги эскалации по порядку. position назначается автоматически (0, 1, 2...).
Доступные типы (type):
notify_persons — уведомить конкретных пользователей
notify_person_next_each_time — round-robin по списку
notify_on_call_from_schedule — кто сейчас на дежурстве по расписанию
notify_user_group — уведомить группу пользователей
notify_team_members — уведомить команду
wait — пауза (duration_seconds секунд)
trigger_webhook — вызвать webhook
resolve — авторезолв инцидента
repeat_escalation — повторить цепочку с начала
Пример:
steps = [
{ type = "notify_on_call_from_schedule", notify_on_call_from_schedule = "<schedule_id>" },
{ type = "wait", duration_seconds = 300 },
{ type = "notify_persons", persons_to_notify = ["<user_id>"] },
{ type = "repeat_escalation" },
]
EOT
type = list(object({
type = string
duration_seconds = optional(number, null)
persons_to_notify = optional(list(string), null)
persons_to_notify_next_each_time = optional(list(string), null)
notify_on_call_from_schedule = optional(string, null)
group_to_notify = optional(string, null)
action_to_trigger = optional(string, null)
notify_to_team_members = optional(string, null)
important = optional(bool, false)
}))
validation {
condition = alltrue([
for s in var.steps : contains([
"notify_persons",
"notify_person_next_each_time",
"notify_on_call_from_schedule",
"notify_user_group",
"notify_team_members",
"wait",
"trigger_webhook",
"resolve",
"repeat_escalation",
"declare_incident",
"notify_whole_channel",
"notify_if_time_from_to",
"notify_if_num_alerts_in_window",
], s.type)
])
error_message = "Недопустимый тип шага эскалации. Проверь список допустимых значений в описании переменной."
}
}

View File

@ -0,0 +1,7 @@
terraform {
required_providers {
grafana = {
source = "grafana/grafana"
}
}
}