Hi Team,
I am trying to capture output of Datadog synthetics monitors id and trying to create SLO based on those output monitor ID’s. However I was facing issue with for_each set. Need little help here to let me understand .
resource "datadog_synthetics_test" "insights_apps" {
for_each = var.actuator
assertion {
operator = "lessThan"
target = "2000"
type = "responseTime"
}
assertion {
operator = "is"
target = "200"
type = "statusCode"
}
assertion {
operator = "is"
property = "content-type"
target = "application/vnd.spring-boot.actuator.v3+json"
type = "header"
}
locations = ["${each.value["location"]}"]
message = "{{#is_alert}}Please check ${each.value["app_name"]} app as it seems to have errors!{{/is_alert}}\n{{^is_alert}}Event Logger App Health Check is passing!{{/is_alert}} \n @slack-Smarsh_1-ea-archive_insights-alerts"
name = "${each.value["app_name"]} Health Check on ${each.value["env"]}"
options_list {
accept_self_signed = "false"
allow_insecure = "false"
follow_redirects = "false"
min_failure_duration = "0"
min_location_failed = "1"
monitor_name = " ${each.value["app_name"]} Health Check on ${each.value["env"]}"
monitor_options {
renotify_interval = "0"
}
monitor_priority = "1"
no_screenshot = "false"
tick_every = "600"
}
request_definition {
dns_server_port = "0"
method = "GET"
no_saving_response_body = "false"
number_of_packets = "0"
port = "0"
should_track_hops = "false"
timeout = "0"
url = each.value["routes"]
}
status = "live"
subtype = "http"
tags = ["${each.value["env"]}"]
type = "api"
}
output "synthetic_ids"{
value = {
for k, v in datadog_synthetics_test.insights_apps : k => v.id
}
}
----- Variable section-----
variable "actuator" {
type = map(object({
app_name = string
location = string
routes = string
env = string
}))
default = {
"US-West-2-Event-Logger" = {
app_name = "event-logging"
location = "aws:us-west-2"
routes = "https://test2.com"
env = "us-west-2"
}
"US-West-2-Archive-Insights" = {
app_name = "archive-recon"
location = "aws:us-west-2"
routes = "https://test.com"
env = "us-west-2"
}
}
}
---------------- SLO Section ----------
resource "datadog_service_level_objective" "insights_apps_slo" {
groups = []
for_each = datadog_synthetics_test.insights_apps
monitor_ids = [each.value.id]
name = "Test ${each.key}"
type = "monitor"
tags = [
"sst:insights",
]
thresholds {
target = 90
timeframe = "7d"
warning = 0
}
}
-------------------- Errors -----------------------
╷
│ Error: Incorrect attribute value type
│
│ on actuator-tests/slo.tf line 4, in resource "datadog_service_level_objective" "insights_apps_slo":
│ 4: monitor_ids = [each.value.id]
│ ├────────────────
│ │ each.value.id is "yyq-23s-bbr"
│
│ Inappropriate value for attribute "monitor_ids": a number is required.
╵
╷
│ Error: Incorrect attribute value type
│
│ on actuator-tests/slo.tf line 4, in resource "datadog_service_level_objective" "insights_apps_slo":
│ 4: monitor_ids = [each.value.id]
│ ├────────────────
│ │ each.value.id is "83k-7s6-bst"
│
│ Inappropriate value for attribute "monitor_ids": a number is required.