Add dashboard UID auto-generation and Gitea CI workflow
Some checks failed
terraform-dev / validate (push) Failing after 1m53s
terraform-dev / plan (push) Has been skipped
terraform-dev / apply (push) Has been skipped

This commit is contained in:
Alexandr
2026-03-25 06:41:19 +03:00
parent 345c5786b3
commit 558a23d916
83 changed files with 53372 additions and 1 deletions

View File

@ -0,0 +1,22 @@
locals {
# Group folders by whether they should keep manual changes or be protected from destruction
folders_ignore_only = {
for group in var.groups : group.dashboard_alert_group_name => group
if lookup(group, "keep_manual_changes", false) && !lookup(group, "prevent_destroy_on_recreate", false)
}
folders_protect_only = {
for group in var.groups : group.dashboard_alert_group_name => group
if !lookup(group, "keep_manual_changes", false) && lookup(group, "prevent_destroy_on_recreate", false)
}
folders_ignore_and_protect = {
for group in var.groups : group.dashboard_alert_group_name => group
if lookup(group, "keep_manual_changes", false) && lookup(group, "prevent_destroy_on_recreate", false)
}
folders_standard = {
for group in var.groups : group.dashboard_alert_group_name => group
if !lookup(group, "keep_manual_changes", false) && !lookup(group, "prevent_destroy_on_recreate", false)
}
}

View File

@ -0,0 +1,44 @@
# Folders with both manual changes allowed and destroy protection
resource "grafana_folder" "folders_ignore_and_protect" {
for_each = local.folders_ignore_and_protect
title = each.value.dashboard_alert_group_name
org_id = var.org_id
lifecycle {
ignore_changes = [title]
prevent_destroy = true
}
}
# Folders with only manual changes allowed
resource "grafana_folder" "folders_ignore_only" {
for_each = local.folders_ignore_only
title = each.value.dashboard_alert_group_name
org_id = var.org_id
lifecycle {
ignore_changes = [title]
}
}
# Folders with only destroy protection
resource "grafana_folder" "folders_protect_only" {
for_each = local.folders_protect_only
title = each.value.dashboard_alert_group_name
org_id = var.org_id
lifecycle {
prevent_destroy = true
}
}
# Standard folders without any special lifecycle management
resource "grafana_folder" "folders_standard" {
for_each = local.folders_standard
title = each.value.dashboard_alert_group_name
org_id = var.org_id
}

View File

@ -0,0 +1,21 @@
# Output for mapping of alert group names to folder IDs
output "folder_ids" {
description = "Mapping of alert group names to their folder IDs in Grafana"
value = merge(
{ for group_name, folder in grafana_folder.folders_ignore_and_protect : group_name => folder.id },
{ for group_name, folder in grafana_folder.folders_ignore_only : group_name => folder.id },
{ for group_name, folder in grafana_folder.folders_protect_only : group_name => folder.id },
{ for group_name, folder in grafana_folder.folders_standard : group_name => folder.id }
)
}
# Output for mapping of alert group names to folder UIDs
output "folder_uids" {
description = "Mapping of alert group names to their folder UIDs in Grafana"
value = merge(
{ for group_name, folder in grafana_folder.folders_ignore_and_protect : group_name => folder.uid },
{ for group_name, folder in grafana_folder.folders_ignore_only : group_name => folder.uid },
{ for group_name, folder in grafana_folder.folders_protect_only : group_name => folder.uid },
{ for group_name, folder in grafana_folder.folders_standard : group_name => folder.uid }
)
}

View File

@ -0,0 +1,16 @@
variable "groups" {
description = "List of alert groups with their definitions"
type = list(object({
dashboard_alert_group_name = string
alert_definitions_path = string
dashboard_path_if_exist = optional(string, null)
keep_manual_changes = optional(bool, false)
prevent_destroy_on_recreate = optional(bool, false)
alerts_on_datasources_uid = list(string)
}))
}
variable "org_id" {
description = "ID of the Grafana organization"
type = string
}

View File

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