Iterating over a map containing a list

Hi all,

I have a variable as described below, in which we can specify a database name per team, per environment:

variable "app_databases" {
  description = "databases per env, per team."
  type        = map(any)
  default = {
    test = {
      team1 = [
      team2 = [
    accept = {
    prod = {

I’m trying to iterate through this variable to apply to a module that take two parameters, the team name and the application:

module "example-postgres-db" {
  source = "../app-db"


The application name in the list is always unique per environment. Depending on which environment it’s being run in, I get the appropriate map with:

locals {
  # Extract the right environment
  env_db = lookup(var.app_databases, terraform.workspace)

How can I iterate over local.env_db in the module such that the map key is the team name and the list of applications is passed one at a time as the application variable? I though about creating a local data structure where I create a map of application = team, since the application name in unique, but nothing I’ve tried so far works. Am I going about this the wrong way or should the structure of the variable change?

Thanks in advance!