From 5b6c436421fc4a32457153d8ec9546c4e6a8e60f Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Wed, 12 Jun 2024 12:52:08 -0300 Subject: [PATCH] [config] Add squad intermediate abstraction --- examples/config/main.tf | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/config/main.tf b/examples/config/main.tf index cc1d523..f3476f5 100644 --- a/examples/config/main.tf +++ b/examples/config/main.tf @@ -3,12 +3,21 @@ provider "opsgenie" { } locals { - # Build a map of our various Opsgenie resources that will be used to iterate over each module - opsgenie_resources = merge([ - for resource_file in fileset(path.cwd, "resources/*.yaml") : { + # load the config for each squad individually + # Temporary variable to hold the config for each squad + squads_configs = [ + for resource_file in fileset(path.cwd, "squads/*/*.yaml") : { for k, v in yamldecode(file(resource_file)) : k => v } - ]...) + ] + + # Build a map of our various Opsgenie resources that will be used to iterate over each module + # by "joining" the configs from many squads into a single map + opsgenie_resources = { + for key in distinct(flatten([for x in local.squads_configs : keys(x)])) : + key => flatten([ + for m, n in local.squads_configs : n[key] if keys(n)[0] == key]) + } } module "opsgenie_config" {