From 50811d98de355f2987d7aaefdee1d9559df7683c Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Tue, 2 Oct 2018 13:53:19 +0200 Subject: [PATCH] MON-301 add support for excluding on service check --- common/alerting-message/{output.tf => outputs.tf} | 0 common/filter-tags/inputs.tf | 9 +++++++-- common/filter-tags/locals.tf | 3 ++- common/filter-tags/output.tf | 9 --------- common/filter-tags/outputs.tf | 10 ++++++++++ 5 files changed, 19 insertions(+), 12 deletions(-) rename common/alerting-message/{output.tf => outputs.tf} (100%) delete mode 100644 common/filter-tags/output.tf create mode 100644 common/filter-tags/outputs.tf diff --git a/common/alerting-message/output.tf b/common/alerting-message/outputs.tf similarity index 100% rename from common/alerting-message/output.tf rename to common/alerting-message/outputs.tf diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf index 3e5abad..9c34609 100644 --- a/common/filter-tags/inputs.tf +++ b/common/filter-tags/inputs.tf @@ -14,12 +14,17 @@ variable "filter_tags_use_defaults" { } variable "filter_tags_custom" { - description = "Tags used for custom filtering when filter_tags_use_defaults is false" + description = "Tags used for custom filtering when filter_tags_use_defaults is false (i.e. \"tag1:val1,tag2:val2\")" default = "*" } +variable "filter_tags_custom_excluded" { + description = "Tags excluded for custom filtering when filter_tags_use_defaults is false (i.e. \"tag1:val1,tag2:val2\")" + default = "" +} + variable "extra_tags" { - description = "Extra optional tags (i.e. [\"tag1:val1\", \"tag2:val2\"])" + description = "Extra optional tags added for default filtering when filter_tags_use_defaults is true (i.e. [\"tag1:val1\", \"tag2:val2\"])" type = "list" default = [] } diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf index fa392da..5289a3f 100644 --- a/common/filter-tags/locals.tf +++ b/common/filter-tags/locals.tf @@ -1,3 +1,4 @@ locals { - filters = "${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}"}" + 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}")))}" } diff --git a/common/filter-tags/output.tf b/common/filter-tags/output.tf deleted file mode 100644 index d0d086b..0000000 --- a/common/filter-tags/output.tf +++ /dev/null @@ -1,9 +0,0 @@ -output "query_alert" { - description = "The full filtering pattern including parentheses for service check monitor type" - value = "{${local.filters}}" -} - -output "service_check" { - description = "The full filtering pattern including braces for query alert monitor type" - value = "(\"${replace(local.filters, ",", "\",\"")}\")" -} diff --git a/common/filter-tags/outputs.tf b/common/filter-tags/outputs.tf new file mode 100644 index 0000000..15a660a --- /dev/null +++ b/common/filter-tags/outputs.tf @@ -0,0 +1,10 @@ +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))))))}}" +} + +output "service_check" { + description = "The full filtering pattern including braces for query alert monitor type" + #value = "over.(\"${replace(local.including, ",", "\",\"")}\").exclude(\"${replace(local.excluding, ",", "\",\"")}\")" + value = ".over(\"${replace(local.including, ",", "\",\"")}\")${local.excluding == "" ? "" : ".exclude(\"${replace(local.excluding, ",", "\",\"")}\")"}" +}