While creating google_monitoring_alert_policy, I keep getting the following error
Inappropriate value for attribute "notification_channels": list of string required.
here is an excerpt from
main.tf
resource "google_monitoring_notification_channel" "activeplaceworkspace_email" {
count = length(var.notification_email_addresses)
display_name = "DevOps Alerts on ${element(var.notification_email_addresses, count.index)}"
type = "email"
labels = {
email_address = element(var.notification_email_addresses, count.index)
}
}
resource "google_monitoring_alert_policy" "disk_alert_policy" {
display_name = "${var.prefix} - Disk utilization, sda1 (80%)"
combiner = "OR"
conditions {
display_name = "${var.prefix} - Disk utilization, sda1 (80%)"
condition_threshold {
filter = "metric.type=\"agent.googleapis.com/disk/percent_used\" resource.type=\"gce_instance\" metric.label.\"device\"=\"sda1\" metric.label.\"state\"=\"used\" metadata.user_labels.\"type\"=\"web-server\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 80
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_MEAN"
}
}
}
notification_channels = [
google_monitoring_notification_channel.workspace_email.*.id,
"google_monitoring_notification_channel.workspace_slack.name"
]
}
variables.tf
variable "notification_email_addresses" {
description = "Email addresses to be notified."
type = list(string)
default = [
"a@mail.com",
"t1@mail.com",
"da@mail.com",
"23@mail.com"
]
}
What Works?
if take only one
notification_channels = google_monitoring_notification_channel.activeplaceworkspace_email.*.id
But two or multiple notification channel values do not work with []
, I think the main issue is with []
.
Your current use of notification_channels
creates a list containing a list and a string in the form of:
notification_channels = [list, string]
Instead it should be a list of strings, which you should be able to obtained using concat method:
notification_channels = concat(
google_monitoring_notification_channel.workspace_email.*.id,
[google_monitoring_notification_channel.workspace_slack.name])