diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b130656..5c7ac09 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ stages: - deploy auto_update: - image: qmanfroi/datadog-terraform:latest + image: claranet/datadog-terraform:latest stage: test script: - ./scripts/auto_update.sh ./ diff --git a/README.md b/README.md index 3a2515e..a53577c 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ After any change on this repo, you need to run the `./scripts/auto_update.sh ./` ### Terraform ### -Version >= 0.12 is required to use these modules of monitors. +Here is the minimum version required to use these modules of integrations. ``` terraform { - required_version = "~> 0.12" + required_version = ">= 0.12.6" } ``` diff --git a/caas/kubernetes/node/monitors-k8s-node.tf b/caas/kubernetes/node/monitors-k8s-node.tf index 16f1f19..a7da3a3 100644 --- a/caas/kubernetes/node/monitors-k8s-node.tf +++ b/caas/kubernetes/node/monitors-k8s-node.tf @@ -66,7 +66,7 @@ resource "datadog_monitor" "memory_pressure" { message = coalesce(var.memory_pressure_message, var.message) type = "service check" -query = < ${var.unregister_net_device_threshold_critical} EOQ @@ -215,7 +215,7 @@ resource "datadog_monitor" "node_unschedulable" { message = coalesce(var.node_unschedulable_message, var.message) type = "metric alert" -query = < 0 diff --git a/caas/kubernetes/workload/monitors-k8s-workload.tf b/caas/kubernetes/workload/monitors-k8s-workload.tf index 326722d..d7e0509 100644 --- a/caas/kubernetes/workload/monitors-k8s-workload.tf +++ b/caas/kubernetes/workload/monitors-k8s-workload.tf @@ -66,7 +66,7 @@ resource "datadog_monitor" "replica_available" { message = coalesce(var.replica_available_message, var.message) type = "query alert" -query = < ${var.swap_threshold_critical} diff --git a/cloud/aws/elasticache/redis/monitors-redis.tf b/cloud/aws/elasticache/redis/monitors-redis.tf index 7d5b170..39f18ce 100644 --- a/cloud/aws/elasticache/redis/monitors-redis.tf +++ b/cloud/aws/elasticache/redis/monitors-redis.tf @@ -69,7 +69,7 @@ resource "datadog_monitor" "redis_replication_lag" { message = coalesce(var.replication_lag_message, var.message) type = "query alert" -query = < ${var.replication_lag_threshold_critical} @@ -103,7 +103,7 @@ resource "datadog_monitor" "redis_commands" { message = coalesce(var.commands_message, var.message) type = "query alert" -query = < ${var.cpu_threshold_critical} diff --git a/cloud/aws/elb/monitors-elb.tf b/cloud/aws/elb/monitors-elb.tf index 9b82f7a..33bafe2 100644 --- a/cloud/aws/elb/monitors-elb.tf +++ b/cloud/aws/elb/monitors-elb.tf @@ -75,7 +75,7 @@ resource "datadog_monitor" "ELB_too_much_5xx" { message = coalesce(var.elb_5xx_message, var.message) type = "query alert" -query = < ${var.replicalag_threshold_critical} diff --git a/cloud/azure/apimanagement/monitors-azure-apimanagement.tf b/cloud/azure/apimanagement/monitors-azure-apimanagement.tf index 9a9829e..f283d31 100644 --- a/cloud/azure/apimanagement/monitors-azure-apimanagement.tf +++ b/cloud/azure/apimanagement/monitors-azure-apimanagement.tf @@ -70,7 +70,7 @@ resource "datadog_monitor" "apimgt_other_requests" { message = coalesce(var.other_requests_message, var.message) type = "query alert" -query = < ${var.high_threads_count_threshold_critical} diff --git a/cloud/azure/iothubs/monitors-iothubs.tf b/cloud/azure/iothubs/monitors-iothubs.tf index 0f4e251..2dcb1a0 100644 --- a/cloud/azure/iothubs/monitors-iothubs.tf +++ b/cloud/azure/iothubs/monitors-iothubs.tf @@ -78,7 +78,7 @@ resource "datadog_monitor" "too_many_query_jobs_failed" { message = coalesce(var.failed_queryjobs_rate_message, var.message) type = "query alert" -query = < ${var.api_latency_threshold_critical} diff --git a/cloud/azure/mysql/monitors-mysql.tf b/cloud/azure/mysql/monitors-mysql.tf index cbde937..189f834 100644 --- a/cloud/azure/mysql/monitors-mysql.tf +++ b/cloud/azure/mysql/monitors-mysql.tf @@ -72,7 +72,7 @@ resource "datadog_monitor" "mysql_io_consumption" { message = coalesce(var.io_consumption_message, var.message) type = "query alert" -query = < ${var.io_consumption_threshold_critical} @@ -106,7 +106,7 @@ resource "datadog_monitor" "mysql_memory_usage" { message = coalesce(var.memory_usage_message, var.message) type = "query alert" -query = < ${var.memory_usage_threshold_critical} diff --git a/cloud/azure/postgresql/monitors-postegresql.tf b/cloud/azure/postgresql/monitors-postegresql.tf index dd9ef50..59f3597 100644 --- a/cloud/azure/postgresql/monitors-postegresql.tf +++ b/cloud/azure/postgresql/monitors-postegresql.tf @@ -67,7 +67,7 @@ resource "datadog_monitor" "postgresql_free_storage" { message = coalesce(var.free_storage_message, var.message) type = "query alert" -query = < ${var.io_consumption_threshold_critical} diff --git a/cloud/azure/redis/monitors-azure-redis.tf b/cloud/azure/redis/monitors-azure-redis.tf index 8916549..66ab051 100644 --- a/cloud/azure/redis/monitors-azure-redis.tf +++ b/cloud/azure/redis/monitors-azure-redis.tf @@ -67,7 +67,7 @@ resource "datadog_monitor" "percent_processor_time" { message = coalesce(var.percent_processor_time_message, var.message) type = "query alert" -query = < ${var.percent_processor_time_threshold_critical} @@ -101,7 +101,7 @@ resource "datadog_monitor" "server_load" { message = coalesce(var.server_load_rate_message, var.message) type = "query alert" -query = < ${var.server_load_rate_threshold_critical} diff --git a/cloud/azure/serverfarms/monitors-azure-serverfarms.tf b/cloud/azure/serverfarms/monitors-azure-serverfarms.tf index 01ac7a8..811ba99 100644 --- a/cloud/azure/serverfarms/monitors-azure-serverfarms.tf +++ b/cloud/azure/serverfarms/monitors-azure-serverfarms.tf @@ -67,7 +67,7 @@ resource "datadog_monitor" "memory_percentage" { message = coalesce(var.memory_percentage_message, var.message) type = "query alert" -query = < ${var.memory_percentage_threshold_critical} diff --git a/cloud/azure/servicebus/monitors-service-bus.tf b/cloud/azure/servicebus/monitors-service-bus.tf index 2185dbd..682af32 100644 --- a/cloud/azure/servicebus/monitors-service-bus.tf +++ b/cloud/azure/servicebus/monitors-service-bus.tf @@ -62,7 +62,7 @@ resource "datadog_monitor" "service_bus_user_errors" { message = coalesce(var.user_errors_message, var.message) type = "query alert" -query = < ${var.diskspace_threshold_critical} @@ -101,7 +101,7 @@ resource "datadog_monitor" "sql-database_dtu_consumption_high" { message = coalesce(var.dtu_message, var.message) type = "query alert" -query = < ${var.dtu_threshold_critical} diff --git a/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf b/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf index 57cd58e..cdb565a 100644 --- a/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf +++ b/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf @@ -72,7 +72,7 @@ resource "datadog_monitor" "sql_elasticpool_dtu_consumption_high" { message = coalesce(var.dtu_message, var.message) type = "query alert" -query = < ${var.dtu_threshold_critical} diff --git a/cloud/azure/storage/monitors-azure-storage.tf b/cloud/azure/storage/monitors-azure-storage.tf index 2e84dc0..d467a49 100644 --- a/cloud/azure/storage/monitors-azure-storage.tf +++ b/cloud/azure/storage/monitors-azure-storage.tf @@ -74,7 +74,7 @@ resource "datadog_monitor" "fileservices_requests_error" { count = var.successful_requests_enabled == "true" ? 1 : 0 name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Azure Storage File service too few successful requests {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = coalesce(var.successful_requests_message, var.message) - query = < ${var.conversion_errors_threshold_critical} diff --git a/cloud/azure/virtual-machine/monitors-virtual-machine.tf b/cloud/azure/virtual-machine/monitors-virtual-machine.tf index 7b5a093..5e11960 100644 --- a/cloud/azure/virtual-machine/monitors-virtual-machine.tf +++ b/cloud/azure/virtual-machine/monitors-virtual-machine.tf @@ -67,7 +67,7 @@ resource "datadog_monitor" "virtualmachine_credit_cpu_remaining_too_low" { message = coalesce(var.cpu_remaining_rate_message, var.message) type = "query alert" -query = < ${var.scanned_bytes_threshold_critical} @@ -118,7 +118,7 @@ resource "datadog_monitor" "scanned_bytes_billed" { message = coalesce(var.scanned_bytes_billed_message, var.message) type = "query alert" -query = < ${var.scanned_bytes_billed_threshold_critical} @@ -229,7 +229,7 @@ resource "datadog_monitor" "table_count" { message = coalesce(var.table_count_message, var.message) type = "metric alert" -query = < ${var.table_count_threshold_critical} @@ -266,7 +266,7 @@ resource "datadog_monitor" "uploaded_bytes" { message = coalesce(var.uploaded_bytes_message, var.message) type = "query alert" -query = < ${var.uploaded_bytes_threshold_critical} diff --git a/cloud/gcp/cloud-sql/common/monitors-cloud-sql-common.tf b/cloud/gcp/cloud-sql/common/monitors-cloud-sql-common.tf index 551d798..528715e 100644 --- a/cloud/gcp/cloud-sql/common/monitors-cloud-sql-common.tf +++ b/cloud/gcp/cloud-sql/common/monitors-cloud-sql-common.tf @@ -81,22 +81,15 @@ resource "datadog_monitor" "disk_utilization_forecast" { message = coalesce(var.disk_utilization_forecast_message, var.message) type = "query alert" -query = <= ${var.disk_utilization_forecast_threshold_critical} EOQ @@ -170,21 +163,14 @@ resource "datadog_monitor" "memory_utilization_forecast" { type = "query alert" query = <= ${var.memory_utilization_forecast_threshold_critical} EOQ @@ -220,7 +206,7 @@ resource "datadog_monitor" "failover_unavailable" { message = coalesce(var.failover_unavailable_message, var.message) type = "metric alert" - query = < ${var.backend_latency_service_threshold_critical} @@ -120,7 +120,7 @@ resource "datadog_monitor" "backend_latency_bucket" { message = coalesce(var.backend_latency_bucket_message, var.message) type = "query alert" -query = < ${var.backend_latency_bucket_threshold_critical} diff --git a/database/elasticsearch/monitors-elasticsearch.tf b/database/elasticsearch/monitors-elasticsearch.tf index 6d0b31f..740f20d 100644 --- a/database/elasticsearch/monitors-elasticsearch.tf +++ b/database/elasticsearch/monitors-elasticsearch.tf @@ -78,7 +78,7 @@ resource "datadog_monitor" "cluster_initializing_shards" { message = coalesce(var.cluster_initializing_shards_message, var.message) type = "metric alert" -query = < ${var.cluster_initializing_shards_threshold_critical} @@ -113,7 +113,7 @@ resource "datadog_monitor" "cluster_relocating_shards" { message = coalesce(var.cluster_relocating_shards_message, var.message) type = "metric alert" -query = < ${var.cluster_relocating_shards_threshold_critical} @@ -222,7 +222,7 @@ resource "datadog_monitor" "jvm_heap_memory_usage" { message = coalesce(var.jvm_heap_memory_usage_message, var.message) type = "query alert" -query = < ${var.jvm_heap_memory_usage_threshold_critical} @@ -257,7 +257,7 @@ resource "datadog_monitor" "jvm_memory_young_usage" { message = coalesce(var.jvm_memory_young_usage_message, var.message) type = "query alert" -query = < ${var.jvm_memory_young_usage_threshold_critical} @@ -362,7 +362,7 @@ resource "datadog_monitor" "jvm_gc_young_collection_latency" { message = coalesce(var.jvm_gc_young_collection_latency_message, var.message) type = "query alert" -query = < ${var.jvm_gc_young_collection_latency_threshold_critical} @@ -398,7 +398,7 @@ resource "datadog_monitor" "indexing_latency" { type = "query alert" // TODO add tags to filter by node type and do not apply this monitor on non-data nodes -query = < ${var.indexing_latency_threshold_critical} @@ -518,7 +518,7 @@ resource "datadog_monitor" "search_query_latency" { type = "query alert" // TODO add tags to filter by node type and do not apply this monitor on non-data nodes -query = < ${var.search_query_latency_threshold_critical} @@ -554,7 +554,7 @@ resource "datadog_monitor" "fetch_latency" { type = "query alert" // TODO add tags to filter by node type and do not apply this monitor on non-data nodes -query = < ${var.fetch_latency_threshold_critical} @@ -660,7 +660,7 @@ resource "datadog_monitor" "field_data_evictions_change" { type = "query alert" // TODO add tags to filter by node type and do not apply this monitor on non-data nodes -query = < ${var.field_data_evictions_change_threshold_critical} @@ -696,7 +696,7 @@ resource "datadog_monitor" "query_cache_evictions_change" { type = "query alert" // TODO add tags to filter by node type and do not apply this monitor on non-data nodes -query = < ${var.query_cache_evictions_change_threshold_critical} diff --git a/database/mongodb/monitors-mongo.tf b/database/mongodb/monitors-mongo.tf index d40d33a..f7bcc32 100644 --- a/database/mongodb/monitors-mongo.tf +++ b/database/mongodb/monitors-mongo.tf @@ -8,6 +8,7 @@ resource "datadog_monitor" "mongodb_primary" { ${var.mongodb_primary_aggregator}(${var.mongodb_primary_timeframe}): min:mongodb.replset.state${module.filter-tags.query_alert} by {replset_name} >= 2 EOQ + evaluation_delay = var.evaluation_delay new_host_delay = var.new_host_delay notify_no_data = true @@ -64,7 +65,7 @@ resource "datadog_monitor" "mongodb_server_count" { message = coalesce(var.mongodb_server_count_message, var.message) type = "metric alert" -query = < 99 @@ -97,7 +98,7 @@ resource "datadog_monitor" "mongodb_replication" { message = coalesce(var.mongodb_replication_message, var.message) type = "metric alert" -query = < ${var.mongodb_lag_critical} EOQ diff --git a/database/mysql/monitors-mysql.tf b/database/mysql/monitors-mysql.tf index 2699cf0..c9787be 100644 --- a/database/mysql/monitors-mysql.tf +++ b/database/mysql/monitors-mysql.tf @@ -69,7 +69,7 @@ resource "datadog_monitor" "mysql_aborted" { message = coalesce(var.mysql_aborted_message, var.message) type = "query alert" -query = < ${var.postgresql_lock_threshold_critical} diff --git a/database/redis/monitors-redis.tf b/database/redis/monitors-redis.tf index f0681b1..26703f7 100644 --- a/database/redis/monitors-redis.tf +++ b/database/redis/monitors-redis.tf @@ -73,7 +73,7 @@ resource "datadog_monitor" "expirations" { message = coalesce(var.expirations_rate_message, var.message) type = "query alert" -query = < ${var.expirations_rate_threshold_critical} @@ -107,7 +107,7 @@ resource "datadog_monitor" "blocked_clients" { message = coalesce(var.blocked_clients_message, var.message) type = "query alert" -query = < ${var.mem_frag_threshold_critical} @@ -245,7 +245,7 @@ resource "datadog_monitor" "rejected_connections" { message = coalesce(var.rejected_con_message, var.message) type = "query alert" -query = < ${var.rejected_con_threshold_critical} diff --git a/scripts/00_requirements.sh b/scripts/00_requirements.sh new file mode 100755 index 0000000..9889c2d --- /dev/null +++ b/scripts/00_requirements.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -u + +source "$(dirname $0)/utils.sh" +goto_root + +function check_command() { + local cmd="$1" + if ! command -v ${cmd} > /dev/null 2>&1; then + echo "This requires ${cmd} command, please install it first." + exit 1 + fi +} + +function verlte() { + [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] +} + +function verlt() { + [ "$1" = "$2" ] && return 1 || verlte $1 $2 +} + +function check_version() { + if [[ "$1" == "terraform" ]]; then + tmp_dir=$(mktemp -d) + cd ${tmp_dir} + cur_ver=$(terraform version | head -n 1 | cut -d' ' -f2) + cur_ver=${cur_ver#"v"} + cd - > /dev/null + rm -fr ${tmp_dir} + req_ver=$(grep required_version README.md | awk '{print $4}') + req_ver=${req_ver%'"'} + elif [[ "$1" == "terraform-docs" ]]; then + req_ver="0.6.0" + cur_ver=$(terraform-docs --version) + else + return + fi + if ! verlte $req_ver $cur_ver; then + echo "This requires at least version ${req_ver} of $1, please upgrade (current version is ${cur_ver})" + exit 2 + fi +} + +for cmd in terraform terraform-docs; do + check_command $cmd + check_version $cmd +done diff --git a/scripts/99_terraform.sh b/scripts/99_terraform.sh index 786abf7..da0a4be 100755 --- a/scripts/99_terraform.sh +++ b/scripts/99_terraform.sh @@ -31,11 +31,7 @@ EOF terraform init ${dir} terraform validate ${dir} rm -f ${dir}/tmp.tf - # hack to work around bug https://github.com/hashicorp/terraform/issues/21434 - # TODO when fixed, remove this bloc and add "terraform fmt -recursive" to the end of this file - for file in $(grep ' = < ${var.disk_space_threshold_critical} @@ -103,21 +103,14 @@ resource "datadog_monitor" "disk_space_forecast" { message = coalesce(var.disk_space_forecast_message, var.message) type = "query alert" -query = <= ${var.disk_space_forecast_threshold_critical} EOQ