resource "google_monitoring_custom_service" "customsrv" {
for_each = var.custom_service_level
display_name = each.value.service_display_name
service_id = each.value.service_id
project = var.project_id
}
// Google Monitoring SLO objects can support many different metric types, for more info see our documenation.
resource "google_monitoring_slo" "custom_request_based_slo" {
for_each = var.custom_sli
service = google_monitoring_custom_service.customsrv[each.key].service_id
display_name = each.value.metric_display_name
goal = each.value.goal
rolling_period_days = each.value.rolling_period_days // Replacable with calendar_period = "DAY", "WEEK", "FORTNIGHT", or "MONTH"
request_based_sli {
// Alternate implementation could use distribution_cut instead of good_total_ratio.
good_total_ratio {
// Any combination of two elements: good_service_filter, bad_service_filter, total_service_filter.
good_service_filter = join(" AND ", each.value.good_service_filter)
total_service_filter = join(" AND ", each.value.total_service_filter)
}
}
depends_on = [ google_monitoring_custom_service.customsrv ]
}
======================
using .tfvars values:-
=======================
custom_service_level = {
"composer-service" = {
service_id = "custom-srv-slos"
service_display_name = "My Custom SLO"
}
}
custom_sli = {
"composer-health" = {
metric_display_name = "test slo with service based SLI"
goal = 0.9
rolling_period_days = 28
window_period = "300s"
good_service_filter = [
"metric.type="composer.googleapis.com/workflow/run_count"",
"resource.type="cloud_composer_workflow"",
"metric.labels.state="success"",
],
total_service_filter = [
"metric.type="composer.googleapis.com/workflow/run_count"",
"resource.type="cloud_composer_workflow"",
]
},
}
=============================== variables used ====================== variable “custom_service_level” { type = map(object({ service_id = string, service_display_name = string, })) } variable “custom_sli” { type = map(object({ metric_display_name = string, goal = number, rolling_period_days = number, good_service_filter = list(string), total_service_filter = list(string) # service = string })) }
getting this error on plan:-
│ Error: Invalid index
│
│ on main.tf line 600, in resource "google_monitoring_slo" "custom_request_based_slo":
│ 600: service = google_monitoring_custom_service.customsrv[each.key].service_id
│ ├────────────────
│ │ each.key is "composer-health"
│ │ google_monitoring_custom_service.customsrv is object with 1 attribute "composer-service"
│
│ The given key does not identify an element in this collection value.
╵
New contributor
Ayub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.