Hi All,
I want to create one list of IP addresses from multiple IP lists in a yaml file. The yaml file looks like:
tenants:
- key: "customer1"
name: "customer1"
ip_allowlist: ["1.2.3.0/24","5.6.7.0/24"]
- key: "customer2"
name: "customer2"
ip_allowlist: ["192.168.222.0/24","192.168.100.0/24"]
What I want to do is construct a new list like this:
“1.2.3.0/24”,“5.6.7.0/24”,“192.168.222.0/24”,“192.168.100.0/24”
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:
[
[
"1.2.3.0/24",
"5.6.7.0/24",
],
[
"192.168.222.0/24",
"192.168.100.0/24",
],
]
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