Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Feature/support address prefix as array #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@ module "route_table" {
## route_table
(Required) The routing table object describing the route table configuration
Mandatory properties are:
- name
- at least one route_entries item as follow:
- name (type=string)
- route_entries (type=object)
- name (type=string)
- prefix (type=string or type=array)
- next_hop_type (type=string)
- next_hop_in_ip_address (type=string)
```hcl
re1= {
name = "myroute1"
prefix = "255.0.0.0/8"
next_hop_type = "None"
next_hop_in_ip_address = "192.168.10.5" #required if next_hop_type is "VirtualAppliance"

},
},
re2= {
name = "myroute1"
prefix = ["10.10.1.0/24","10.10.2.0/24"]
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "192.168.10.5" #required if next_hop_type is "VirtualAppliance"

},
```
Optional fields:
- disable_bgp_route_propagation
Expand Down
20 changes: 17 additions & 3 deletions module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ resource "azurerm_route_table" "route_table" {
disable_bgp_route_propagation = lookup(var.route_table, "disable_bgp_route_propagation", null)

dynamic "route" {
for_each = var.route_table.route_entries
for_each = flatten(
[
for route_key,route_value in var.route_table.route_entries :
[
for address_key, address_value in flatten(list(route_value.prefix)): # flatten(list()) handles support for both array & string
{
name = replace(join("-",list(route_value.name,address_value)),"/","_") # build name from route table name + address prefix, escape slash
address_prefix = address_value
next_hop_type = route_value.next_hop_type
next_hop_in_ip_address = route_value.next_hop_type == "VirtualAppliance" ? (var.next_hop_in_dynamic_private_ip != null && var.next_hop_in_dynamic_private_ip != "null" && var.next_hop_in_dynamic_private_ip != "" ? var.next_hop_in_dynamic_private_ip : route_value.next_hop_in_ip_address) : null
}
]
]
)

content {
name = route.value.name
address_prefix = route.value.prefix
address_prefix = route.value.address_prefix
next_hop_type = route.value.next_hop_type
next_hop_in_ip_address = route.value.next_hop_type == "VirtualAppliance" ? (var.next_hop_in_dynamic_private_ip != null && var.next_hop_in_dynamic_private_ip != "null" && var.next_hop_in_dynamic_private_ip != "" ? var.next_hop_in_dynamic_private_ip : route.value.next_hop_in_ip_address) : null
next_hop_in_ip_address = route.value.next_hop_in_ip_address
}
}
}