属性 "notification_channels" 的值不合适:元素 0:字符串
Inappropriate value for attribute "notification_channels": element 0: string
创建 google_monitoring_alert_policy 时,我不断收到以下错误
属性“notification_channels”的值不合适:需要字符串列表。
这里摘自
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"
]
}
什么有效?
如果只拿一个
notification_channels = google_monitoring_notification_channel.activeplaceworkspace_email.*.id
但是两个或多个通知渠道值不适用于 []
,我认为主要问题在于 []
。
您当前对 notification_channels
的使用会创建一个列表,其中包含一个列表和一个字符串,格式为:
notification_channels = [list, string]
相反,它应该是一个字符串列表,您应该可以使用 concat 方法获得它:
notification_channels = concat(
google_monitoring_notification_channel.workspace_email.*.id,
[google_monitoring_notification_channel.workspace_slack.name])
创建 google_monitoring_alert_policy 时,我不断收到以下错误
属性“notification_channels”的值不合适:需要字符串列表。
这里摘自
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"
]
}
什么有效?
如果只拿一个
notification_channels = google_monitoring_notification_channel.activeplaceworkspace_email.*.id
但是两个或多个通知渠道值不适用于 []
,我认为主要问题在于 []
。
您当前对 notification_channels
的使用会创建一个列表,其中包含一个列表和一个字符串,格式为:
notification_channels = [list, string]
相反,它应该是一个字符串列表,您应该可以使用 concat 方法获得它:
notification_channels = concat(
google_monitoring_notification_channel.workspace_email.*.id,
[google_monitoring_notification_channel.workspace_slack.name])