Using multiple nested and non-nested variables

I’m trying to use terrform to create a datadog dashboard, where:

  1. There are multiple sections (CPU, RAM, etc.)
  2. Under each section, there are graphs for different parformance metrics (system load, etc.) that will have lines for each host

I was able to create a simple .tf file, run terraform apply and see the dashboard created with just one graph and one host, i.e. where the information was hardcoded. I came up with the code below, but am at a bit of a loss as to how to access the variables in the resource section. I’m keeping the code simple for now, so I can establish a baseline.

Any thoughts on how I’d access the variables correctly?


# Datadog Performance Dashboard

locals {
	dashboard_title = "Title here"
	hosts = toset( [ "host1" "host2"] )
	params = {
		"CPU" = [
			{
			title = "System Load - 1 min avg"
			dd_param = "avg:system.load.norm.1"
			}
		]
		"RAM" = [
			{
			title = "Memory Commit limit"
			dd_param = "system.mem.commit_limit"
			}
		]
	}
}

resource "datadog_dashboard" "ordered_dashboard" {
    title         = var.dashboard_title
    description   = "Created using the Datadog provider in Terraform"
    layout_type   = "ordered"
    is_read_only  = true


    dynamic "widget" {
        for_each = local.params
		category = each.key
        content {
            timeseries_definition {
            	title = title(each.value.specify-first-element-in-array-here.title)
            	request {
                	q = "each.value.specify-element-in-array-here.dd_param{host:host1}"
                	display_type = "line"
                	style {
                    	line_type = "solid"
                	}
            	}
        	}
        }
    }

}