Hello there I’m trying to create an GCP alert using more than 1 condition using a nested map(object) variable.
here is my variable:
new_alert = {
alert01 = {
alert_displayname = "terraform-hdfs_datanodes_down"
combiner_var = "OR"
notification_channels_var = [
"projects/mckesson-test-env/notificationChannels/18428528452968721018",
"projects/mckesson-test-env/notificationChannels/17359140270922751940"
]
user_labels_var = "bar"
project_id = "mckesson-test-env"
all_conditions = {
condition01 = {
condition_displayname= "terraform-test-condition 2"
filter_alert="metric.type=\"dataproc.googleapis.com/cluster/hdfs/datanodes\" resource.type=\"cloud_dataproc_cluster\" metric.label.\"status\"=\"running\""
comparison_var="COMPARISON_LT"
threshold_value_var=2
duration_var="60s"
aligment_period_var="60s"
per_series_aligner_var="ALIGN_MEAN"
},
condition02 = {
condition_displayname= "terraform-test-condition 3"
filter_alert="metric.type=\"router.googleapis.com/nat/allocated_ports\" resource.type=\"nat_gateway\""
comparison_var="COMPARISON_GT"
threshold_value_var=4
duration_var="120s"
aligment_period_var="120s"
per_series_aligner_var="ALIGN_MEAN"
},
}
},
}
and here is my main code:
resource “google_monitoring_alert_policy” “new_alert” {
for_each = var.new_alert
display_name = each.value[“alert_displayname”] #alert policy name
combiner = each.value[“combiner_var”]
notification_channels = [
for noti in each.value ["notification_channels_var"] :
noti
]
project = each.value[“project_id”]
conditions {
for key, value in each.value : [ #getting an error here
display_name = each.value["condition_displayname"] #Metric name
condition_threshold {
filter = each.value["filter_alert"]
comparison = each.value["comparison_var"] #Configuration>Condition triggers if>any time series violates> is above
threshold_value = each.value["threshold_value_var"]
duration = each.value["duration_var"]
aggregations {
alignment_period = each.value["aligment_period_var"]
per_series_aligner = each.value["per_series_aligner_var"]
}
}
]
}
user_labels = {
foo = each.value["user_labels_var"]
}
}
I’m getting error in this loop
for key, value in each.value : [ #getting an error here
anyone knows how to do a loop in a nested map of objects?