From e564cf068d3811f828ee96debf99f243521fd461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Respaut?= Date: Tue, 2 Oct 2018 15:39:11 +0200 Subject: [PATCH] MON-301: Refactor a bit terraform code with intermediate locals --- common/filter-tags/locals.tf | 7 +++++-- common/filter-tags/outputs.tf | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf index 5289a3f..9e6d8cf 100644 --- a/common/filter-tags/locals.tf +++ b/common/filter-tags/locals.tf @@ -1,4 +1,7 @@ locals { - including = "${var.filter_tags_use_defaults == "true" ? join(",", compact(concat(split(",", format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment)), compact(var.extra_tags)))) : "${var.filter_tags_custom}"}" - excluding = "${join(",", compact(split(",", "${var.filter_tags_custom_excluded}")))}" + including_default_list = "${compact(concat(split(",", format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment)), compact(var.extra_tags)))}" + excluding_list = "${compact(split(",", "${var.filter_tags_custom_excluded}"))}" + + including_string = "${var.filter_tags_use_defaults == "true" ? join(",", local.including_default_list) : "${var.filter_tags_custom}"}" + excluding_string = "${join(",", local.excluding_list)}" } diff --git a/common/filter-tags/outputs.tf b/common/filter-tags/outputs.tf index 9eb9fc6..f64a661 100644 --- a/common/filter-tags/outputs.tf +++ b/common/filter-tags/outputs.tf @@ -1,14 +1,14 @@ output "query_alert" { description = "The full filtering pattern including parentheses for service check monitor type" - value = "{${join(",", compact(concat(list(local.including), formatlist("!%s", compact(split(",", local.excluding))))))}}" + value = "{${join(",", compact(concat(list(local.including_string), formatlist("!%s", local.excluding_list))))}}" } output "service_check" { description = "The full filtering pattern including braces for query alert monitor type" - value = ".over(\"${replace(local.including, ",", "\",\"")}\")${local.excluding == "" ? "" : ".exclude(\"${replace(local.excluding, ",", "\",\"")}\")"}" + value = ".over(\"${replace(local.including_string, ",", "\",\"")}\")${local.excluding_string == "" ? "" : ".exclude(\"${replace(local.excluding_string, ",", "\",\"")}\")"}" } output "event_alert" { description = "The full filtering pattern for event alert monitor type" - value = "tags:${local.including}${local.excluding == "" ? "" : " excluded_tags:${local.excluding}"}" + value = "tags:${local.including_string}${local.excluding_string == "" ? "" : " excluded_tags:${local.excluding_string}"}" }