Create new list from multiple list from yaml file

Hi All,

I want to create one list of IP addresses from multiple IP lists in a yaml file. The yaml file looks like:

  - key: "customer1"
    name: "customer1"
    ip_allowlist: ["",""]
  - key: "customer2"
    name: "customer2"
    ip_allowlist: ["",""]

What I want to do is construct a new list like this:

The list has to go into the addresses field below:

resource "aws_wafv2_ip_set" "example" {
  name               = "example"
  description        = "example"
  scope              = "CLOUDFRONT"
  ip_address_version = "IPV4"
  addresses          = LIST_OF_IP_ADDRESS

I use the yaml file to create other resources with for_each but I have no idea on how to create the new list. Is this possible? Does anyone know how to do this?

This is what I have so far:

I create a local var with the subnets of all customers:

locals {
  IP_addresses = [for tenant in local.tenants_acc_config.tenants : tenant.ip_allowlist_frontend]

If I output this var I get:


Then I use these lists in the addresses like this:
addresses = concat(local.IP_addresses[0],local.IP_addresses[1])

There must be a better way to do this. Whenever a new customer is added to the yaml file I want the addresses to be updated automatically.

I also tried this:
addresses = concat(local.IP_addresses[*])

But this gives an error:
**Error:** **Incorrect attribute value type**
**local.IP_addreses** is tuple with 2 elements

After hours of googling and trying I fixed it with the flatten function like this:
addresses = flatten(concat(local.IP_addreses[*]))