I'm using the pagerduty_ruleset_rule resource in combination with count
to create multiple PagerDuty rules. Each rule is devised from a count.index
of the services
list of maps.
Variable definition - services
list of maps (passed in as a var.services
):
variable "services" {
type = list(object({ id = string, service_tags = list(string) }))
description = "List of service IDs and tags to route events to"
}
Resource definition - pagerduty_ruleset_rule
:
resource "pagerduty_ruleset_rule" "rule" {
count = length(var.services)
ruleset = pagerduty_ruleset.custom_ruleset.id
position = count.index
disabled = false
conditions {
operator = "or"
subconditions {
operator = "contains"
parameter {
path = "payload.group"
value = "service:${var.services[count.index].service_tags[0]}"
}
}
subconditions {
operator = "contains"
parameter {
path = "payload.group"
value = "service:${var.services[count.index].service_tags[1]}"
}
}
}
actions {
route {
value = var.services[count.index].id
}
}
}
Notice how I have separate subconditions
maps for each element in service_tags
.
Is there a way to dynamically create subconditions
maps based on the size of the service_tags
list?
In the above code snippet, I assume that the size of the list is 2 (indexes [0]
& [1]
), but I'd like this to be dynamic - having the number of subconditions
be equal to the size of the service_tags
list.