Hi Team,
I am using four dynamic widgets within main dynamic widget and I have so many api id’s called within these widget to create each resources, due to which I get a lengthy resource being printed and its too huge to be saved in back end . Is there a way to reduce the number of resources being printed here or an alternative option ?
locals {
egress_test_avail_slo_names = { for k, mod in module.egress_slos : “{k}_test_avail_name" => mod.test_avail_slo_name if var.branch != "prod" }
egress_test_avail_slo_ids = { for k, mod in module.egress_slos : "{k}_test_avail_id” => mod.test_avail_slo_id if var.branch != “prod” }
egress_test_latency_slo_names = { for k, mod in module.egress_slos : “{k}_test_latency_name" => mod.test_latency_slo_name if var.branch != "prod" } egress_test_latency_slo_ids = { for k, mod in module.egress_slos : "{k}_test_latency_id” => mod.test_latency_slo_id if var.branch != “prod” }
egress_prod_avail_slo_names = { for k, mod in module.egress_slos : “{k}_prod_avail_name" => mod.prod_avail_slo_name if var.branch == "prod" } egress_prod_avail_slo_ids = { for k, mod in module.egress_slos : "{k}_prod_avail_id” => mod.prod_avail_slo_id if var.branch == “prod” }
egress_prod_latency_slo_names = { for k, mod in module.egress_slos : “{k}_prod_latency_name" => mod.prod_latency_slo_name if var.branch == "prod" } egress_prod_latency_slo_ids = { for k, mod in module.egress_slos : "{k}_prod_latency_id” => mod.prod_latency_slo_id if var.branch == “prod” }
egress_all_slo_names = var.branch == “prod” ? merge(local.egress_prod_avail_slo_names, local.egress_prod_latency_slo_names) : merge(local.egress_test_avail_slo_names, local.egress_test_latency_slo_names)
egress_all_slo_ids = var.branch == “prod” ? merge(local.egress_prod_avail_slo_ids, local.egress_prod_latency_slo_ids) : merge(local.egress_test_avail_slo_ids, local.egress_test_latency_slo_ids)
}
resource “datadog_dashboard” “egress_slo_dashboard” {
title = “Egress SLO Dashboard - {var.branch == "test" || var.branch == "prod" ? upper(var.branch) : "Dev"} - {local.branch_prefix}”
description = “Created using the Datadog provider in Terraform”
layout_type = “ordered”
tags = [“team:pnc-dwelling”]
dynamic “widget” {
for_each = zipmap(
values(local.egress_all_slo_names),
values(local.egress_all_slo_ids)
)
iterator = slo
content {
group_definition {
layout_type = “ordered”
background_color = “white”
title = “SLO : Dwelling Insurance - ${slo.key}”
dynamic "widget" {
for_each = contains(values(local.egress_test_avail_slo_names), slo.key) || contains(values(local.egress_prod_avail_slo_names), slo.key) ? [1] : []
content {
service_level_objective_definition {
title = "Availability SLO : Dwelling Insurance - ${slo.key} "
title_size = "16"
title_align = "left"
slo_id = slo.value
view_type = "detail"
view_mode = "overall"
time_windows = ["30d", "7d", "90d"]
show_error_budget = true
}
widget_layout {
height = 3
width = 4
x = 0
y = 0
}
}
}
dynamic "widget" {
for_each = contains(values(local.egress_test_latency_slo_names), slo.key) || contains(values(local.egress_prod_latency_slo_names), slo.key) ? [1] : []
content {
service_level_objective_definition {
title = "Latency SLO : Dwelling Insurance - ${slo.key} "
title_size = "16"
title_align = "center"
slo_id = slo.value
view_type = "detail"
view_mode = "overall"
time_windows = ["30d", "7d", "90d"]
show_error_budget = true
}
widget_layout {
height = 3
width = 12
x = 0
y = 0
}
}
}
dynamic "widget" {
for_each = contains(values(local.egress_test_avail_slo_names), slo.key) || contains(values(local.egress_prod_avail_slo_names), slo.key) ? [1] : []
content {
query_value_definition {
title = "Slo Status for SLO ${slo.key}"
title_size = "16"
title_align = "left"
request {
query {
slo_query {
data_source = "slo"
measure = "slo_status"
slo_id = slo.value
group_mode = "overall"
slo_query_type = "metric"
name = "my_slo_query"
additional_query_filters = ""
}
}
}
autoscale = true
precision = 2
timeseries_background {
type = "area"
}
}
widget_layout {
height = 3
width = 4
x = 4
y = 0
}
}
}
dynamic "widget" {
for_each = contains(values(local.egress_test_avail_slo_ids), slo.value) || contains(values(local.egress_prod_avail_slo_ids), slo.value) ? [1] : []
content {
timeseries_definition {
title = "Slo Status for SLO ${slo.key}"
title_size = "16"
title_align = "left"
show_legend = true
legend_layout = "auto"
legend_columns = ["avg", "min", "max", "value", "sum"]
request {
query {
slo_query {
data_source = "slo"
measure = "slo_status"
slo_id = slo.value
group_mode = "overall"
slo_query_type = "metric"
name = "my_slo_query"
additional_query_filters = ""
}
}
display_type = "line"
}
}
widget_layout {
height = 3
width = 4
x = 8
y = 0
}
}
}
}
}
}
}