diff --git a/README.md b/README.md index a0c8506..e2e947a 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,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/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..5f19e92 --- /dev/null +++ b/common/filter-tags/README.md @@ -0,0 +1,46 @@ +# 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 | +| 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 | + +## 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..3e5abad --- /dev/null +++ b/common/filter-tags/inputs.tf @@ -0,0 +1,25 @@ +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 = "*" +} + +variable "extra_tags" { + description = "Extra optional tags (i.e. [\"tag1:val1\", \"tag2:val2\"])" + type = "list" + default = [] +} diff --git a/common/filter-tags/locals.tf b/common/filter-tags/locals.tf new file mode 100644 index 0000000..fa392da --- /dev/null +++ b/common/filter-tags/locals.tf @@ -0,0 +1,3 @@ +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}"}" +} diff --git a/common/filter-tags/output.tf b/common/filter-tags/output.tf new file mode 100644 index 0000000..d0d086b --- /dev/null +++ b/common/filter-tags/output.tf @@ -0,0 +1,9 @@ +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/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)"