Merged in MON-273_add_module_for_filter_tags (pull request #123)
MON-273 add module for filter tags Approved-by: Alexandre Gaillet <alexandre.gaillet@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: Quentin Manfroi <quentin.manfroi@yahoo.fr>
This commit is contained in:
commit
cd26c5259a
@ -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/)
|
||||
|
||||
@ -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)
|
||||
|
||||
46
common/filter-tags/README.md
Normal file
46
common/filter-tags/README.md
Normal file
@ -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 | `<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)
|
||||
|
||||
25
common/filter-tags/inputs.tf
Normal file
25
common/filter-tags/inputs.tf
Normal file
@ -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 = []
|
||||
}
|
||||
3
common/filter-tags/locals.tf
Normal file
3
common/filter-tags/locals.tf
Normal file
@ -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}"}"
|
||||
}
|
||||
9
common/filter-tags/output.tf
Normal file
9
common/filter-tags/output.tf
Normal file
@ -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, ",", "\",\"")}\")"
|
||||
}
|
||||
24
scripts/03_update_module.sh
Executable file
24
scripts/03_update_module.sh
Executable file
@ -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 <<EOF
|
||||
module "filter-tags" {
|
||||
source = "../../common/filter-tags"
|
||||
|
||||
environment = "\${var.environment}"
|
||||
resource = "$resource"
|
||||
filter_tags_use_defaults = "\${var.filter_tags_use_defaults}"
|
||||
filter_tags_custom = "\${var.filter_tags_custom}"
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
cd - >> /dev/null
|
||||
done
|
||||
terraform fmt "$(get_scope $1)"
|
||||
Loading…
x
Reference in New Issue
Block a user