MON-301: Refactor a bit terraform code with intermediate locals

This commit is contained in:
Jérôme Respaut 2018-10-02 15:39:11 +02:00 committed by Quentin Manfroi
parent 5acbe5045c
commit e564cf068d
2 changed files with 8 additions and 5 deletions

View File

@ -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)}"
}

View File

@ -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}"}"
}