Apply terraform fmt for CI
Some checks failed
terraform-dev / validate (push) Failing after 47s
terraform-dev / plan (push) Has been skipped
terraform-dev / apply (push) Has been skipped

This commit is contained in:
Alexandr
2026-03-25 07:31:02 +03:00
parent ed66d17b70
commit 8f0f9b7f47
25 changed files with 317 additions and 317 deletions

View File

@ -4,8 +4,8 @@ terraform {
source = "grafana/grafana" source = "grafana/grafana"
version = ">= 4.7.0" version = ">= 4.7.0"
} }
vault = { vault = {
source = "hashicorp/vault" source = "hashicorp/vault"
} }
} }
} }

View File

@ -5,46 +5,46 @@ locals {
"X-Disable-Provenance" = var.disable_provenance ? "true" : "false" "X-Disable-Provenance" = var.disable_provenance ? "true" : "false"
} }
# Contact points configuration # Contact points configuration
contact_points = [ contact_points = [
{ {
name = "default" name = "default"
type = "slack" type = "slack"
is_default = true is_default = true
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_default"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_default"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-critical" name = "infra-alerts-critical"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_critical"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_critical"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-informational" name = "infra-alerts-informational"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_info"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_info"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-test" name = "infra-alerts-test"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_test"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_test"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
} }
] ]
} }

View File

@ -3,8 +3,8 @@ provider "vault" {
} }
data "vault_kv_secret_v2" "secret_ext" { # Секреты для подключения к внешним источникам (mm, clickhouse и т.д.) data "vault_kv_secret_v2" "secret_ext" { # Секреты для подключения к внешним источникам (mm, clickhouse и т.д.)
mount = "app" mount = "app"
name = "groups/monitoring/grafana/dev/ext" name = "groups/monitoring/grafana/dev/ext"
} }
data "vault_kv_secret_v2" "secret_int" { # Секреты для работы самой графаны data "vault_kv_secret_v2" "secret_int" { # Секреты для работы самой графаны

View File

@ -38,36 +38,36 @@ org_id = "2"
# Alert groups configuration # Alert groups configuration
groups = [ groups = [
{ {
dashboard_alert_group_name = "System Alerts" dashboard_alert_group_name = "System Alerts"
folder_uid = "system" folder_uid = "system"
alert_definitions_path = "alerts/system" alert_definitions_path = "alerts/system"
dashboard_path_if_exist = "dashboards/system" dashboard_path_if_exist = "dashboards/system"
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
alerts_on_datasources_uid = ["prometheus"] alerts_on_datasources_uid = ["prometheus"]
}, },
{ {
dashboard_alert_group_name = "Self monitoring" dashboard_alert_group_name = "Self monitoring"
folder_uid = "self-monitoring" folder_uid = "self-monitoring"
alert_definitions_path = "alerts/self-monitoring" alert_definitions_path = "alerts/self-monitoring"
dashboard_path_if_exist = "dashboards/self-monitoring" dashboard_path_if_exist = "dashboards/self-monitoring"
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
alerts_on_datasources_uid = ["prometheus-local-1"] alerts_on_datasources_uid = ["prometheus-local-1"]
} }
] ]
# Data sources configuration # Data sources configuration
datasources = [ datasources = [
{ {
name = "prometheus" name = "prometheus"
uid = "prometheus" uid = "prometheus"
type = "prometheus" type = "prometheus"
url = "http://localhost:8481/select/0/prometheus" url = "http://localhost:8481/select/0/prometheus"
access_mode = "proxy" access_mode = "proxy"
is_default = true is_default = true
basic_auth = false basic_auth = false
json_data = { json_data = {
timeInterval = "15s" timeInterval = "15s"
} }
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
@ -76,79 +76,79 @@ datasources = [
# Notification policies configuration # Notification policies configuration
notification_policies = [ notification_policies = [
{ {
contact_point = "infra-alerts-critical" contact_point = "infra-alerts-critical"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "disaster" value = "disaster"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-critical" contact_point = "infra-alerts-critical"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "critical" value = "critical"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-informational" contact_point = "infra-alerts-informational"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "warning" value = "warning"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-informational" contact_point = "infra-alerts-informational"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "perfomance" value = "perfomance"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-test" contact_point = "infra-alerts-test"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "status" label = "status"
match = "=" match = "="
value = "test" value = "test"
} }
] ]
} }
] ]

View File

@ -4,8 +4,8 @@ terraform {
source = "grafana/grafana" source = "grafana/grafana"
version = ">= 4.7.0" version = ">= 4.7.0"
} }
vault = { vault = {
source = "hashicorp/vault" source = "hashicorp/vault"
} }
} }
} }

View File

@ -5,46 +5,46 @@ locals {
"X-Disable-Provenance" = var.disable_provenance ? "true" : "false" "X-Disable-Provenance" = var.disable_provenance ? "true" : "false"
} }
# Contact points configuration # Contact points configuration
contact_points = [ contact_points = [
{ {
name = "default" name = "default"
type = "slack" type = "slack"
is_default = true is_default = true
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_default"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_default"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-critical" name = "infra-alerts-critical"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_critical"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_critical"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-informational" name = "infra-alerts-informational"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_info"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_info"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
}, },
{ {
name = "infra-alerts-test" name = "infra-alerts-test"
type = "slack" type = "slack"
is_default = false is_default = false
settings = { settings = {
webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_test"] webhook_url = data.vault_kv_secret_v2.secret_ext.data["mmwebhook_infra_alerts_test"]
template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template" template = "../../../modules/grafana_contact_points/template/alerts_message_mm.template"
} }
} }
] ]
} }

View File

@ -3,8 +3,8 @@ provider "vault" {
} }
data "vault_kv_secret_v2" "secret_ext" { # Секреты для подключения к внешним источникам (mm, clickhouse и т.д.) data "vault_kv_secret_v2" "secret_ext" { # Секреты для подключения к внешним источникам (mm, clickhouse и т.д.)
mount = "app" mount = "app"
name = "groups/monitoring/grafana/dev/ext" name = "groups/monitoring/grafana/dev/ext"
} }
data "vault_kv_secret_v2" "secret_int" { # Секреты для работы самой графаны data "vault_kv_secret_v2" "secret_int" { # Секреты для работы самой графаны

View File

@ -38,36 +38,36 @@ org_id = "35"
# Alert groups configuration # Alert groups configuration
groups = [ groups = [
{ {
dashboard_alert_group_name = "System Alerts" dashboard_alert_group_name = "System Alerts"
folder_uid = "system" folder_uid = "system"
alert_definitions_path = "alerts/system" alert_definitions_path = "alerts/system"
dashboard_path_if_exist = "dashboards/system" dashboard_path_if_exist = "dashboards/system"
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
alerts_on_datasources_uid = ["prometheus"] alerts_on_datasources_uid = ["prometheus"]
}, },
{ {
dashboard_alert_group_name = "Self monitoring" dashboard_alert_group_name = "Self monitoring"
folder_uid = "self-monitoring" folder_uid = "self-monitoring"
alert_definitions_path = "alerts/self-monitoring" alert_definitions_path = "alerts/self-monitoring"
dashboard_path_if_exist = "dashboards/self-monitoring" dashboard_path_if_exist = "dashboards/self-monitoring"
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
alerts_on_datasources_uid = ["prometheus-local-1"] alerts_on_datasources_uid = ["prometheus-local-1"]
} }
] ]
# Data sources configuration # Data sources configuration
datasources = [ datasources = [
{ {
name = "prometheus" name = "prometheus"
uid = "prometheus" uid = "prometheus"
type = "prometheus" type = "prometheus"
url = "http://localhost:8481/select/0/prometheus" url = "http://localhost:8481/select/0/prometheus"
access_mode = "proxy" access_mode = "proxy"
is_default = true is_default = true
basic_auth = false basic_auth = false
json_data = { json_data = {
timeInterval = "15s" timeInterval = "15s"
} }
keep_manual_changes = false keep_manual_changes = false
prevent_destroy_on_recreate = false prevent_destroy_on_recreate = false
@ -76,79 +76,79 @@ datasources = [
# Notification policies configuration # Notification policies configuration
notification_policies = [ notification_policies = [
{ {
contact_point = "infra-alerts-critical" contact_point = "infra-alerts-critical"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "disaster" value = "disaster"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-critical" contact_point = "infra-alerts-critical"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "critical" value = "critical"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-informational" contact_point = "infra-alerts-informational"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "warning" value = "warning"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-informational" contact_point = "infra-alerts-informational"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "severity" label = "severity"
match = "=" match = "="
value = "perfomance" value = "perfomance"
}, },
{ {
label = "team" label = "team"
match = "=" match = "="
value = "infra" value = "infra"
} }
] ]
}, },
{ {
contact_point = "infra-alerts-test" contact_point = "infra-alerts-test"
continue = true continue = true
matchers = [ matchers = [
{ {
label = "status" label = "status"
match = "=" match = "="
value = "test" value = "test"
} }
] ]
} }
] ]

View File

@ -18,9 +18,9 @@ resource "grafana_contact_point" "contact_points" {
dynamic "slack" { dynamic "slack" {
for_each = each.value.type == "slack" ? [1] : [] for_each = each.value.type == "slack" ? [1] : []
content { content {
url = each.value.settings["webhook_url"] url = each.value.settings["webhook_url"]
title = try(local.contact_point_templates[each.value.name].title, null) title = try(local.contact_point_templates[each.value.name].title, null)
text = local.contact_point_templates[each.value.name].template text = local.contact_point_templates[each.value.name].template
} }
} }
} }

View File

@ -1,4 +1,4 @@
output "contact_point_ids" { output "contact_point_ids" {
description = "Mapping of contact point names to their IDs" description = "Mapping of contact point names to their IDs"
value = { for k, v in grafana_contact_point.contact_points : k => v.id } value = { for k, v in grafana_contact_point.contact_points : k => v.id }
} }

View File

@ -1,6 +1,6 @@
variable "contact_points" { variable "contact_points" {
description = "List of contact points for Grafana alerts" description = "List of contact points for Grafana alerts"
type = list(object({ type = list(object({
name = string name = string
type = string type = string
settings = map(string) settings = map(string)

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ locals {
parent_folder_name = length(split("/", group.dashboard_alert_group_name)) > 1 ? join("/", slice(split("/", group.dashboard_alert_group_name), 0, length(split("/", group.dashboard_alert_group_name)) - 1)) : null parent_folder_name = length(split("/", group.dashboard_alert_group_name)) > 1 ? join("/", slice(split("/", group.dashboard_alert_group_name), 0, length(split("/", group.dashboard_alert_group_name)) - 1)) : null
folder_title = length(split("/", group.dashboard_alert_group_name)) > 1 ? element(split("/", group.dashboard_alert_group_name), length(split("/", group.dashboard_alert_group_name)) - 1) : group.dashboard_alert_group_name folder_title = length(split("/", group.dashboard_alert_group_name)) > 1 ? element(split("/", group.dashboard_alert_group_name), length(split("/", group.dashboard_alert_group_name)) - 1) : group.dashboard_alert_group_name
# Get parent folder UID from parent group's folder_uid # Get parent folder UID from parent group's folder_uid
parent_folder_uid = length(split("/", group.dashboard_alert_group_name)) > 1 ? try(local.groups_by_name[join("/", slice(split("/", group.dashboard_alert_group_name), 0, length(split("/", group.dashboard_alert_group_name)) - 1))].folder_uid, null) : null parent_folder_uid = length(split("/", group.dashboard_alert_group_name)) > 1 ? try(local.groups_by_name[join("/", slice(split("/", group.dashboard_alert_group_name), 0, length(split("/", group.dashboard_alert_group_name)) - 1))].folder_uid, null) : null
} }
} }

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
variable "contact_points" { variable "contact_points" {
description = "List of contact points" description = "List of contact points"
type = list(object({ type = list(object({
name = string name = string
type = string type = string
is_default = optional(bool, false) is_default = optional(bool, false)
labels = optional(map(string)) labels = optional(map(string))
settings = map(string) settings = map(string)
})) }))
} }
@ -46,31 +46,31 @@ variable "repeat_interval" {
variable "notification_policies" { variable "notification_policies" {
description = "Routing rules for specific label sets" description = "Routing rules for specific label sets"
type = list(object({ type = list(object({
contact_point = string contact_point = string
continue = optional(bool) continue = optional(bool)
group_by = optional(list(string)) group_by = optional(list(string))
group_wait = optional(string) group_wait = optional(string)
group_interval = optional(string) group_interval = optional(string)
repeat_interval = optional(string) repeat_interval = optional(string)
matchers = list(object({ matchers = list(object({
label = string label = string
match = string # Allowed operators are = for equality, != for negated equality, =~ for regex equality, and !~ for negated regex equality match = string # Allowed operators are = for equality, != for negated equality, =~ for regex equality, and !~ for negated regex equality
value = string value = string
})) }))
policies = optional(list(object({ policies = optional(list(object({
contact_point = string contact_point = string
continue = optional(bool) continue = optional(bool)
group_by = optional(list(string)) group_by = optional(list(string))
group_wait = optional(string) group_wait = optional(string)
group_interval = optional(string) group_interval = optional(string)
repeat_interval = optional(string) repeat_interval = optional(string)
matchers = list(object({ matchers = list(object({
label = string label = string
match = string match = string
value = string value = string
})) }))
})), []) })), [])
})) }))
default = [] default = []
} }

View File

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

View File

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

View File

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