Referencing a generated resource in a var list of objects

I’m trying to build out an Azure firewall, some public IP’s and some NAT rules associated with them.

I’m running into difficulty referencing the public IP’s i’ve made in the resource in my nat rules. Since the nat rules use a count and then a nested for_each loop I can’t figure out how to have them properly reference the public IP they will be using.

My current attempt is I add the name of the public_ip manually in the var.firewall_nat_collection and am trying to filter the azurerm_public_ip.rg_public_IPs but this only returns an empty field and doesn’t seem to match.

  destination_addresses = [for ip_address, name in azurerm_public_ip.rg_public_IPs : ip_address if name == rule.value.public_ip]

Let me know what is wrong with my for statement or if there is a better way to achieve this?

relevant code:

Hi @Altern1ty!

Could you please add a little more information about what happened when you tried the example you shared, and how that differed from the result you expected? That sort of information is important so we can be sure what you’re asking.