
# Module for managing datasources
module "grafana_datasource01" {
  source      = "../../modules/grafana_datasource"
  datasources = var.datasources
  org_id      = var.org_id
  providers = {
    grafana = grafana.grafana01
  }
}

# Module for managing folders
module "grafana_dashboard_folder01" {
  source = "../../modules/grafana_dashboard_folder"
  groups = var.groups
  org_id = var.org_id
  providers = {
    grafana = grafana.grafana01
  }
}

# Module for managing dashboards
module "grafana_dashboard01" {
  source                   = "../../modules/grafana_dashboard"
  groups                   = var.groups
  org_id                   = var.org_id
  folder_ids               = module.grafana_dashboard_folder01.folder_ids
  dashboard_uid_max_length = var.dashboard_uid_max_length
  depends_on               = [module.grafana_dashboard_folder01]
  providers = {
    grafana = grafana.grafana01
  }
}

# Module for managing contact points
module "grafana_contact_points01" {
  source         = "../../modules/grafana_contact_points"
  org_id         = var.org_id
  env            = var.env
  grafana_url    = "https://grafana.pvenode.ru/"
  contact_points = local.contact_points
  providers = {
    grafana = grafana.grafana01
  }
}

# Module for managing notification policies
module "grafana_notification_policies01" {
  source                = "../../modules/grafana_notification_policies"
  org_id                = var.org_id
  contact_points        = local.contact_points
  notification_policies = var.notification_policies
  depends_on            = [module.grafana_contact_points01]
  providers = {
    grafana = grafana.grafana01
  }
}

# Module for managing rule group
module "grafana_rule_group01" {
  source      = "../../modules/grafana_rule_group"
  org_id      = var.org_id
  groups      = var.groups
  folder_uids = module.grafana_dashboard_folder01.folder_uids
  datasources = var.datasources
  providers = {
    grafana = grafana.grafana01
  }

  # Time-related parameters
  interval_seconds            = var.interval_seconds
  default_interval_ms         = var.default_interval_ms
  default_alert_duration      = var.default_alert_duration
  default_evaluation_interval = var.default_evaluation_interval
  default_time_range_from     = var.default_time_range_from
  default_processing_range    = var.default_processing_range
  default_max_data_points     = var.default_max_data_points
  default_no_data_state       = var.default_no_data_state
  default_exec_err_state      = var.default_exec_err_state

  depends_on = [
    module.grafana_datasource01,
    module.grafana_notification_policies01,
    module.grafana_dashboard_folder01,
    module.grafana_contact_points01
  ]
}
