diff --git a/common/alerting-message/README.md b/common/alerting-message/README.md index 49ac413..96d42f3 100644 --- a/common/alerting-message/README.md +++ b/common/alerting-message/README.md @@ -40,3 +40,4 @@ Creates a DataDog monitor alert message with the following inputs : ## Related documentation +Datadog notifications official documentation: [https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning](https://docs.datadoghq.com/monitors/notifications/?tab=is_alertis_warning) 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/README.md b/common/filter-tags/README.md index 5f19e92..f79e8c4 100644 --- a/common/filter-tags/README.md +++ b/common/filter-tags/README.md @@ -22,14 +22,16 @@ Creates all kinds of filters tags patterns depending of the monitor type and dir * A filter tags pattern for service check * A filter tags pattern for query alert +* A filter tags pattern for event alert ## Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | environment | Architecture Environment | string | - | yes | -| extra_tags | Extra optional tags (i.e. ["tag1:val1", "tag2:val2"]) | list | `` | no | -| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| extra_tags | Extra optional tags added for default filtering when filter_tags_use_defaults is true (i.e. ["tag1:val1", "tag2:val2"]) | list | `[]` | no | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false (i.e. "tag1:val1,tag2:val2") | string | `*` | no | +| filter_tags_custom_excluded | Tags excluded for custom filtering when filter_tags_use_defaults is false (i.e. "tag1:val1,tag2:val2") | string | `` | no | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | resource | The dedicated tag for the resource | string | - | yes | @@ -37,6 +39,7 @@ Creates all kinds of filters tags patterns depending of the monitor type and dir | Name | Description | |------|-------------| +| event_alert | The full filtering pattern for event alert monitor type | | query_alert | The full filtering pattern including parentheses for service check monitor type | | service_check | The full filtering pattern including braces for query alert monitor type | 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..d153e77 100644 --- a/common/filter-tags/locals.tf +++ b/common/filter-tags/locals.tf @@ -1,3 +1,7 @@ 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_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_use_defaults == "true" ? "" : join(",", 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/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..c70bbdc --- /dev/null +++ b/common/filter-tags/outputs.tf @@ -0,0 +1,20 @@ +# Inputs example values: +#TF_VAR_environment='prod' TF_VAR_resource='nginx' TF_VAR_filter_tags_use_defaults=false TF_VAR_filter_tags_custom="tag:val,tag2:val2" TF_VAR_filter_tags_custom_excluded="excludedtag:value,exludedtag2:value2" terraform apply + +# query_alert = {tag:val,tag2:val2,!excludedtag:value,!exludedtag2:value2} +output "query_alert" { + description = "The full filtering pattern including parentheses for service check monitor type" + value = "{${join(",", compact(concat(list(local.including_string), formatlist("!%s", local.excluding_list))))}}" +} + +# service_check = .over("tag:val","tag2:val2").exclude("excludedtag:value","exludedtag2:value2") +output "service_check" { + description = "The full filtering pattern including braces for query alert monitor type" + value = ".over(\"${replace(local.including_string, ",", "\",\"")}\")${local.excluding_string == "" ? "" : ".exclude(\"${replace(local.excluding_string, ",", "\",\"")}\")"}" +} + +# event_alert = tags:tag:val,tag2:val2 excluded_tags:excludedtag:value,exludedtag2:value2 +output "event_alert" { + description = "The full filtering pattern for event alert monitor type" + value = "tags:${local.including_string}${local.excluding_string == "" ? "" : " excluded_tags:${local.excluding_string}"}" +}