diff --git a/cloud/gcp/pubsub/inputs.tf b/cloud/gcp/pubsub/inputs.tf new file mode 100644 index 0000000..eeb6013 --- /dev/null +++ b/cloud/gcp/pubsub/inputs.tf @@ -0,0 +1,118 @@ +# +# Datadog global variables +# +variable "environment" { + description = "Architecture environment" + 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 "message" { + description = "Message sent when a monitor is triggered" +} + +variable "delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 +} + +# +# Filter variables +# +variable "project_id" { + type = "string" + description = "ID of the GCP Project" +} + +# +# Sending Operations Count +# +variable "sending_operations_count_message" { + description = "Custom message for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "" +} + +variable "sending_operations_count_time_aggregator" { + description = "Timeframe for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "sum" +} + +variable "sending_operations_count_timeframe" { + description = "Timeframe for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "last_30m" +} + +variable "sending_operations_count_threshold_critical" { + description = "Critical threshold" + type = "string" + default = 0 +} + +variable "sending_operations_count_silenced" { + description = "Groups to mute for GCP Pub/Sub Sending Operations Count monitor" + type = "map" + default = {} +} + +variable "sending_operations_count_extra_tags" { + description = "Extra tags for GCP Pub/Sub Sending Operations Count monitor" + type = "list" + default = [] +} + +# +# Unavailable Sending Operations Count +# +variable "unavailable_sending_operations_count_message" { + description = "Custom message for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "" +} + +variable "unavailable_sending_operations_count_time_aggregator" { + description = "Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "sum" +} + +variable "unavailable_sending_operations_count_timeframe" { + description = "Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "last_10m" +} + +variable "unavailable_sending_operations_count_threshold_warning" { + description = "Warning threshold" + type = "string" + default = 2 +} + +variable "unavailable_sending_operations_count_threshold_critical" { + description = "Critical threshold" + type = "string" + default = 4 +} + +variable "unavailable_sending_operations_count_silenced" { + description = "Groups to mute for GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "map" + default = {} +} + +variable "unavailable_sending_operations_count_extra_tags" { + description = "Extra tags for GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "list" + default = [] +} diff --git a/cloud/gcp/pubsub/monitors-pubsub.tf b/cloud/gcp/pubsub/monitors-pubsub.tf new file mode 100644 index 0000000..6ea5b34 --- /dev/null +++ b/cloud/gcp/pubsub/monitors-pubsub.tf @@ -0,0 +1,99 @@ +# +# FILTER +# +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? + format("project_id:%s", var.project_id) : + "${var.filter_tags_custom}"}" + } +} + +# +# Sending Operations Count +# +resource "datadog_monitor" "sending_operations_count" { + name = "[${var.environment}] GCP pubsub sending messages operations {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + message = "${coalesce(var.sending_operations_count_message, var.message)}" + + type = "query alert" + + query = <= ${var.unavailable_sending_operations_count_threshold_critical} +EOF + + thresholds { + warning = "${var.unavailable_sending_operations_count_threshold_warning}" + critical = "${var.unavailable_sending_operations_count_threshold_critical}" + } + + notify_audit = false + locked = false + timeout_h = 0 + include_tags = true + no_data_timeframe = 25 + require_full_window = false + notify_no_data = true + renotify_interval = 0 + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.delay}" + + silenced = "${var.unavailable_sending_operations_count_silenced}" + + tags = [ + "team:gcp", + "provider:gcp", + "resource:pubsub", + "env:${var.environment}", + "created_by:terraform", + "${var.unavailable_sending_operations_count_extra_tags}", + ] +}