hello
I have a yaml file I need to decode, I have the single values working but need help with the multiple values
here is my yaml file
---
rules:
- name: "test1234"
priority: 1010
direction: "Inbound"
access: "Allow"
protocol: "*"
source_port_range:
- "135"
- "137"
- "139"
source_address_prefix:
- "1.1.1.1"
destination_port_range:
- "*"
destination_address_prefix:
- "2.2.2.2"
- name: "test4567"
priority: 1020
direction: "Outbound"
access: "Allow"
protocol: "tcp"
source_port_range: [ "25", "465", "587" ]
source_address_prefix:
- "2.2.2.2"
- "2.3.2.3"
destination_port_range:
- "*"
destination_address_prefix:
- "*"
here is my terraform
resource "azurerm_network_security_rule" "nsr" {
for_each = { for rule in local.rules : rule.name => rule }
name = lower(each.value.name)
priority = lower(each.value.priority)
direction = lower(each.value.direction)
access = lower(each.value.access)
protocol = lower(each.value.protocol)
source_port_range = lower(each.value[*].source_port_range)
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.rg.name
network_security_group_name = azurerm_network_security_group.nsg.name
}
the problem is I dont know how to pick up multiple values like
source_address_prefix:
- "2.2.2.2"
- "2.3.2.3"
I hope this makes sense, I know this wont work
= lower(each.value[*].source_port_range)
length(lookup(each.value, "source_port_range", [])) == 0 ? null : each.value.source_port_range
any advice where i’m going wrong
thanks in advance