-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathiosxe_routing.tf
More file actions
108 lines (101 loc) · 4.45 KB
/
Copy pathiosxe_routing.tf
File metadata and controls
108 lines (101 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
locals {
# Non-VRF static routes
static_routes = flatten([
for device in local.devices : [
for static_route in try(local.device_config[device.name].routing.static_routes, []) : {
device_name = device.name
prefix = try(static_route.prefix, null)
mask = try(static_route.mask, null)
next_hops = try(length(static_route.next_hops) == 0, true) ? null : [for hop in static_route.next_hops : {
next_hop = try(hop.ip, "${hop.interface_type}${trimprefix(hop.interface_id, "$string ")}", null)
distance = try(hop.distance, null)
global = try(hop.global, null)
name = try(hop.name, null)
permanent = try(hop.permanent, null)
tag = try(hop.tag, null)
} if try(hop.track_id, null) == null]
next_hops_with_track = try(length(static_route.next_hops) == 0, true) ? null : [for hop in static_route.next_hops : {
next_hop = try(hop.ip, "${hop.interface_type}${trimprefix(hop.interface_id, "$string ")}", null)
distance = try(hop.distance, null)
name = try(hop.name, null)
permanent = try(hop.permanent, null)
tag = try(hop.tag, null)
track_id_name = try(hop.track_id, null)
} if try(hop.track_id, null) != null]
key = format("%s/%s/%s", device.name,
try(static_route.prefix, null),
try(static_route.mask, null))
} if try(static_route.vrf, null) == null # Only non-VRF routes
]
])
# VRF static routes grouped by VRF
static_routes_vrf = flatten([
for device in local.devices : [
for vrf_name, vrf_routes in {
for static_route in try(local.device_config[device.name].routing.static_routes, []) :
try(static_route.vrf, "") => static_route...
if try(static_route.vrf, null) != null
} : {
device_name = device.name
vrf = vrf_name
routes = try(length(vrf_routes) == 0, true) ? null : [for static_route in vrf_routes : {
prefix = try(static_route.prefix, null)
mask = try(static_route.mask, null)
next_hops = try(length(static_route.next_hops) == 0, true) ? null : [for hop in static_route.next_hops : {
next_hop = try(hop.ip, "${hop.interface_type}${trimprefix(hop.interface_id, "$string ")}", null)
distance = try(hop.distance, null)
global = try(hop.global, null)
name = try(hop.name, null)
permanent = try(hop.permanent, null)
tag = try(hop.tag, null)
} if try(hop.track_id, null) == null]
next_hops_with_track = try(length(static_route.next_hops) == 0, true) ? null : [for hop in static_route.next_hops : {
next_hop = try(hop.ip, "${hop.interface_type}${trimprefix(hop.interface_id, "$string ")}", null)
distance = try(hop.distance, null)
name = try(hop.name, null)
permanent = try(hop.permanent, null)
tag = try(hop.tag, null)
track_id_name = try(hop.track_id, null)
} if try(hop.track_id, null) != null]
}]
key = format("%s/%s", device.name, vrf_name)
}
]
])
}
resource "iosxe_static_route" "static_route" {
for_each = {
for route in local.static_routes : route.key => route
}
device = each.value.device_name
prefix = each.value.prefix
mask = each.value.mask
next_hops = each.value.next_hops
next_hops_with_track = each.value.next_hops_with_track
depends_on = [
iosxe_interface_ethernet.ethernet,
iosxe_interface_ethernet.ethernet_sub,
iosxe_interface_loopback.loopback,
iosxe_interface_vlan.vlan,
iosxe_interface_port_channel.port_channel,
iosxe_interface_port_channel_subinterface.port_channel_subinterface,
iosxe_interface_tunnel.tunnel
]
}
resource "iosxe_static_routes_vrf" "static_routes_vrf" {
for_each = {
for route_vrf in local.static_routes_vrf : route_vrf.key => route_vrf
}
device = each.value.device_name
vrf = each.value.vrf
routes = each.value.routes
depends_on = [
iosxe_interface_ethernet.ethernet,
iosxe_interface_ethernet.ethernet_sub,
iosxe_interface_loopback.loopback,
iosxe_interface_vlan.vlan,
iosxe_interface_port_channel.port_channel,
iosxe_interface_port_channel_subinterface.port_channel_subinterface,
iosxe_interface_tunnel.tunnel
]
}