resource "datadog_dashboard" "ordered_dashboard" {
title = "SLO Dashboard"
description = "Created using the Datadog provider in Terraform"
layout_type = "ordered"
is_read_only = true
dynamic widget {
for_each = { for index, svc in local.list_of_services : svc.name => svc }
content {
widget_type = "group_definition"
layout_type = "ordered"
title = "${each.value.name}"
background_color = "vivid_green"
}
}
}
I eventually want to have more in each widget but right now I am just trying to get the dynamic block working with the Group definition widget. I have N number of svcs that I want terraform to create 2 widgets in a dashboard for each svc within groups I define.
I am getting widget type, layout type, title, and background color, arent expected here.
The
group_definition
block must exists underwidget.group_definition
as stated in the Terraform documentation. In order to create N numbers of groups definitions per N numbers of services change your code to this:This will create a a group definition per service defined in
locals.list_of_services
.If you want to create N numbers of
group_definition
per service, you can also use the flatten function but you'll need to update the structure of yourlocals
orvariable
, example: