Merged in MON-301-manage-exclude-on-the-module-for (pull request #170)
MON-301 manage exclude on the module for Approved-by: Quentin Manfroi <quentin.manfroi@yahoo.fr> Approved-by: Jérôme Respaut <shr3ps@gmail.com> Approved-by: Patrick Decat <patrick.decat@fr.clara.net> Approved-by: Laurent Piroelle <laurent.piroelle@fr.clara.net> Approved-by: Rafael Romero Carmona <rafael.romero.carmona@fr.clara.net> Approved-by: Alexandre Gaillet <alexandre.gaillet@fr.clara.net>
This commit is contained in:
commit
39ef624418
@ -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)
|
||||
|
||||
@ -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 | `<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 |
|
||||
|
||||
|
||||
@ -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 = []
|
||||
}
|
||||
|
||||
@ -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)}"
|
||||
}
|
||||
|
||||
@ -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, ",", "\",\"")}\")"
|
||||
}
|
||||
20
common/filter-tags/outputs.tf
Normal file
20
common/filter-tags/outputs.tf
Normal file
@ -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}"}"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user