From 35edf309303847a61d654fd13b9e04bc8a224f1e Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 10 Aug 2018 16:57:09 +0200 Subject: [PATCH 1/5] MON-273 add filter tags module --- common/alerting-message/README.md | 19 +++++-------- common/filter-tags/README.md | 45 +++++++++++++++++++++++++++++++ common/filter-tags/inputs.tf | 20 ++++++++++++++ common/filter-tags/locals.tf | 4 +++ common/filter-tags/output.tf | 10 +++++++ 5 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 common/filter-tags/README.md create mode 100644 common/filter-tags/inputs.tf create mode 100644 common/filter-tags/locals.tf create mode 100644 common/filter-tags/output.tf diff --git a/common/alerting-message/README.md b/common/alerting-message/README.md index 2a5d870..49ac413 100644 --- a/common/alerting-message/README.md +++ b/common/alerting-message/README.md @@ -1,8 +1,6 @@ -Alerting Message Datadog Generator -================================== +# ALERTING MESSAGE Datadog Generator -How to use this module ----------------------- +## How to use this module ``` module "datadog-message-alerting" { @@ -14,8 +12,7 @@ module "datadog-message-alerting" { } ``` -Purpose -------- +## Purpose Creates a DataDog monitor alert message with the following inputs : @@ -25,8 +22,7 @@ Creates a DataDog monitor alert message with the following inputs : * Prepend text free string * Append text free string -Inputs ------- +## Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| @@ -36,14 +32,11 @@ Inputs | message_warning | Define a broadcast channel for warning alerts | string | - | yes | | prepend_text | Optional free text string to prepend to alert | string | `` | no | -Outputs -------- +## Outputs | Name | Description | |------|-------------| | alerting-message | The generated message string | -Related documentation ---------------------- +## Related documentation -DataDog documentation: [https://docs.datadoghq.com/integrations/azure_app_services](https://docs.datadoghq.com/integrations/azure_app_services) diff --git a/common/filter-tags/README.md b/common/filter-tags/README.md new file mode 100644 index 0000000..80ce730 --- /dev/null +++ b/common/filter-tags/README.md @@ -0,0 +1,45 @@ +# FILTER TAGS Datadog Generator + +## How to use this module + +This module usage should be transparent because it should be used inside each monitors set directly. +Here is a simple example but it is advisable to see how are created other existing monitors sets: + +``` +module "filter-tags" { + source = "../../common/filter-tags" + + environment = "${var.environment}" + resource = "my_resource" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} +``` + +## Purpose + +Creates all kinds of filters tags patterns depending of the monitor type and directly usable in a monitors set : + +* A filter tags pattern for service check +* A filter tags pattern for query alert + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture Environment | string | - | yes | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | +| resource | The dedicated tag for the resource | string | - | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| 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 | + +## Related documentation + +Datadog API type of monitor: [https://docs.datadoghq.com/api/?lang=python#create-a-monitor](https://docs.datadoghq.com/api/?lang=python#create-a-monitor) + diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf new file mode 100644 index 0000000..5c4da92 --- /dev/null +++ b/common/filter-tags/inputs.tf @@ -0,0 +1,20 @@ +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +variable "resource" { + description = "The dedicated tag for the resource" + type = "string" +} + +variable "filter_tags_use_defaults" { + description = "Use default filter tags convention" + default = "true" +} + +variable "filter_tags_custom" { + description = "Tags used for custom filtering when filter_tags_use_defaults is false" + default = "*" +} + diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf new file mode 100644 index 0000000..2d3834f --- /dev/null +++ b/common/filter-tags/locals.tf @@ -0,0 +1,4 @@ +locals { + filters = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment) : "${var.filter_tags_custom}"}" +} + diff --git a/common/filter-tags/output.tf b/common/filter-tags/output.tf new file mode 100644 index 0000000..e71c0b9 --- /dev/null +++ b/common/filter-tags/output.tf @@ -0,0 +1,10 @@ +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, ",", "\",\"")}\")" +} + From a7b41f6a537f856165fd92bc8c9053231afa0ff9 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 10 Aug 2018 16:59:27 +0200 Subject: [PATCH 2/5] MON-273 auto update and terraform fmt --- README.md | 1 + common/filter-tags/inputs.tf | 1 - common/filter-tags/locals.tf | 1 - common/filter-tags/output.tf | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 81b51a6..c0aa0ef 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [stream-analytics](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/stream-analytics/) - [common](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/) - [alerting-message](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/alerting-message/) + - [filter-tags](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/filter-tags/) - [databases](https://bitbucket.org/morea/terraform.feature.datadog/src/master/databases/) - [mongodb](https://bitbucket.org/morea/terraform.feature.datadog/src/master/databases/mongodb/) - [middleware](https://bitbucket.org/morea/terraform.feature.datadog/src/master/middleware/) diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf index 5c4da92..0108baf 100644 --- a/common/filter-tags/inputs.tf +++ b/common/filter-tags/inputs.tf @@ -17,4 +17,3 @@ variable "filter_tags_custom" { description = "Tags used for custom filtering when filter_tags_use_defaults is false" default = "*" } - diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf index 2d3834f..4ca593a 100644 --- a/common/filter-tags/locals.tf +++ b/common/filter-tags/locals.tf @@ -1,4 +1,3 @@ locals { filters = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment) : "${var.filter_tags_custom}"}" } - diff --git a/common/filter-tags/output.tf b/common/filter-tags/output.tf index e71c0b9..d0d086b 100644 --- a/common/filter-tags/output.tf +++ b/common/filter-tags/output.tf @@ -7,4 +7,3 @@ output "service_check" { description = "The full filtering pattern including braces for query alert monitor type" value = "(\"${replace(local.filters, ",", "\",\"")}\")" } - From faeb0d13bb324278c39e6fe3a7dba77e7983acc6 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 13 Aug 2018 17:17:06 +0200 Subject: [PATCH 3/5] MON-273 add optional extra tags support --- common/filter-tags/README.md | 1 + common/filter-tags/inputs.tf | 8 ++++++++ common/filter-tags/locals.tf | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/filter-tags/README.md b/common/filter-tags/README.md index 80ce730..033701f 100644 --- a/common/filter-tags/README.md +++ b/common/filter-tags/README.md @@ -28,6 +28,7 @@ Creates all kinds of filters tags patterns depending of the monitor type and dir | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | environment | Architecture Environment | string | - | yes | +| extra_tags | Extra optional tags | list | `` | no | | filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | resource | The dedicated tag for the resource | string | - | yes | diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf index 0108baf..82d5192 100644 --- a/common/filter-tags/inputs.tf +++ b/common/filter-tags/inputs.tf @@ -17,3 +17,11 @@ variable "filter_tags_custom" { description = "Tags used for custom filtering when filter_tags_use_defaults is false" default = "*" } + +variable "extra_tags" { + description = "Extra optional tags" + type = "list" + default = [] + + # Example of value to add optional tags : ["tag1:val1", "tag2:val2"] +} diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf index 4ca593a..fa392da 100644 --- a/common/filter-tags/locals.tf +++ b/common/filter-tags/locals.tf @@ -1,3 +1,3 @@ locals { - filters = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_%s:enabled,env:%s", var.resource, var.environment) : "${var.filter_tags_custom}"}" + 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}"}" } From 5b457cc505da15e183d8c5c5a5a5208e82ec3ff4 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Tue, 14 Aug 2018 15:55:45 +0200 Subject: [PATCH 4/5] MON-273 add script to auto add filter tag module --- scripts/03_update_module.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/03_update_module.sh diff --git a/scripts/03_update_module.sh b/scripts/03_update_module.sh new file mode 100755 index 0000000..c5adb5f --- /dev/null +++ b/scripts/03_update_module.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -xueo pipefail + +source "$(dirname $0)/utils.sh" +goto_root + +for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print); do + cd $(dirname $path) + resource="$(basename $(dirname $path))" + if ! [ -f modules.tf ] && grep -q filter_tags_use_defaults inputs.tf; then + cat > modules.tf <> /dev/null +done +terraform fmt "$(get_scope $1)" From f7b414bb84de3f4baec73a4ed8d2211ba5e3a024 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 20 Aug 2018 14:28:59 +0200 Subject: [PATCH 5/5] MON-273 add example in description --- common/filter-tags/README.md | 2 +- common/filter-tags/inputs.tf | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/filter-tags/README.md b/common/filter-tags/README.md index 033701f..5f19e92 100644 --- a/common/filter-tags/README.md +++ b/common/filter-tags/README.md @@ -28,7 +28,7 @@ Creates all kinds of filters tags patterns depending of the monitor type and dir | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | environment | Architecture Environment | string | - | yes | -| extra_tags | Extra optional tags | list | `` | no | +| 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 | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | resource | The dedicated tag for the resource | string | - | yes | diff --git a/common/filter-tags/inputs.tf b/common/filter-tags/inputs.tf index 82d5192..3e5abad 100644 --- a/common/filter-tags/inputs.tf +++ b/common/filter-tags/inputs.tf @@ -19,9 +19,7 @@ variable "filter_tags_custom" { } variable "extra_tags" { - description = "Extra optional tags" + description = "Extra optional tags (i.e. [\"tag1:val1\", \"tag2:val2\"])" type = "list" default = [] - - # Example of value to add optional tags : ["tag1:val1", "tag2:val2"] }