Merge list with another list of map in terraform
We have a list listA and a list of map, mapA as below
listA = ["cluster-0","cluster-1"]


mapA = [
{
  auto_upgrade       = false
  disk_size_gb       = 100
  disk_type          = "pd-standard"
  node_pool_labels            = {
    agentpool = "np-1"
  }
},
{
  auto_upgrade       = false
  disk_size_gb       = 50
  disk_type          = "pd-balanced"
  node_pool_labels            = {
    agentpool = "np-2"
  }
},
{
 auto_upgrade                = false
 disk_size_gb                = 100
 disk_type                   = "pd-standard"
 node_pool_labels            = {
    agentpool = "np-3"
 }
}
]


I am trying to create a new list which should look like
listB = [
"cluster-0" = [{
  auto_upgrade       = false
  disk_size_gb       = 100
  disk_type          = "pd-standard"
  node_pool_labels   = {
      agentpool = "np-1"
   }
 },
 {
  auto_upgrade       = false
  disk_size_gb       = 50
  disk_type          = "pd-balanced"
  node_pool_labels   = {
      agentpool = "np-2"
   }
 },
 {
  auto_upgrade                = false
  disk_size_gb                = 100
  disk_type                   = "pd-standard"
  node_pool_labels            = {
      agentpool = "np-3"
  }
}], 

"cluster-1"= [{
  auto_upgrade       = false
  disk_size_gb       = 100
  disk_type          = "pd-standard"
  node_pool_labels   = {
      agentpool = "np-1"
   }
 },
 {
  auto_upgrade       = false
  disk_size_gb       = 50
  disk_type          = "pd-balanced"
  node_pool_labels   = {
      agentpool = "np-2"
   }
 },
 {
  auto_upgrade                = false
  disk_size_gb                = 100
  disk_type                   = "pd-standard"
  node_pool_labels            = {
      agentpool = "np-3"
  }
}]
] 

I have tried zipmap which works when listA has two elements and mapA has got two elements like only np-1, np-2 but fails when we add np-3. Trying to make this dynamic listB.

How can I create a dynamic list in Terraform that combines a list of strings with a list of maps?
You can use:
listB = [{for idx, value in local.listA: value => local.mapA }]

so iterate over listA to create a new list where the elements are a dict of which the key is the original element in listA, and the value mapA.
