-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnxos_ipv6.tf
More file actions
226 lines (214 loc) · 15.2 KB
/
Copy pathnxos_ipv6.tf
File metadata and controls
226 lines (214 loc) · 15.2 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
locals {
# Group IPv6 routes by device/vrf for the nxos_ipv6 vrfs nested map
ipv6_routes_by_device_vrf = {
for entry in flatten([
for device in local.devices : [
for route in try(local.device_config[device.name].routing.ipv6_routes, []) : {
device = device.name
vrf = try(route.vrf, "default")
route = route
}
]
]) : "${entry.device}/${entry.vrf}" => entry...
}
# Collect all IPv6 interfaces across all interface types as a flat list
ipv6_interfaces = flatten([
for device in local.devices : concat(
# Ethernets (L3 only)
[for int in try(local.device_config[device.name].interfaces.ethernets, []) : {
device = device.name
vrf = try(int.vrf, "default")
id = "eth${int.id}"
ipv6_address_autoconfig = try(int.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(int.ipv6.nd_default_route, null)
ipv6_forward = try(int.ipv6.forward, null)
ipv6_link_local_use_bia = try(int.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(int.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(int.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(int.ipv6.address_link_local, null)
ipv6_addresses = try(int.ipv6.addresses, [])
} if !try(int.switchport.enabled, true) && try(int.channel_group, null) == null
],
# Loopbacks
[for int in try(local.device_config[device.name].interfaces.loopbacks, []) : {
device = device.name
vrf = try(int.vrf, "default")
id = "lo${int.id}"
ipv6_address_autoconfig = try(int.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(int.ipv6.nd_default_route, null)
ipv6_forward = try(int.ipv6.forward, null)
ipv6_link_local_use_bia = try(int.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(int.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(int.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(int.ipv6.address_link_local, null)
ipv6_addresses = try(int.ipv6.addresses, [])
}],
# SVIs
[for int in try(local.device_config[device.name].interfaces.vlans, []) : {
device = device.name
vrf = try(int.vrf, "default")
id = "vlan${int.id}"
ipv6_address_autoconfig = try(int.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(int.ipv6.nd_default_route, null)
ipv6_forward = try(int.ipv6.forward, null)
ipv6_link_local_use_bia = try(int.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(int.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(int.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(int.ipv6.address_link_local, null)
ipv6_addresses = try(int.ipv6.addresses, [])
}],
# Port channels (L3 only)
[for int in try(local.device_config[device.name].interfaces.port_channels, []) : {
device = device.name
vrf = try(int.vrf, "default")
id = "po${int.id}"
ipv6_address_autoconfig = try(int.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(int.ipv6.nd_default_route, null)
ipv6_forward = try(int.ipv6.forward, null)
ipv6_link_local_use_bia = try(int.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(int.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(int.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(int.ipv6.address_link_local, null)
ipv6_addresses = try(int.ipv6.addresses, [])
} if !try(int.switchport.enabled, true)
],
# Subinterfaces (ethernets)
flatten([for int in try(local.device_config[device.name].interfaces.ethernets, []) :
[for sub in try(int.subinterfaces, []) : {
device = device.name
vrf = try(sub.vrf, "default")
id = "eth${int.id}.${sub.id}"
ipv6_address_autoconfig = try(sub.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(sub.ipv6.nd_default_route, null)
ipv6_forward = try(sub.ipv6.forward, null)
ipv6_link_local_use_bia = try(sub.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(sub.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(sub.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(sub.ipv6.address_link_local, null)
ipv6_addresses = try(sub.ipv6.addresses, [])
} if try(sub.ipv6, null) != null]
]),
# Subinterfaces (port channels)
flatten([for int in try(local.device_config[device.name].interfaces.port_channels, []) :
[for sub in try(int.subinterfaces, []) : {
device = device.name
vrf = try(sub.vrf, "default")
id = "po${int.id}.${sub.id}"
ipv6_address_autoconfig = try(sub.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(sub.ipv6.nd_default_route, null)
ipv6_forward = try(sub.ipv6.forward, null)
ipv6_link_local_use_bia = try(sub.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(sub.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(sub.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(sub.ipv6.address_link_local, null)
ipv6_addresses = try(sub.ipv6.addresses, [])
} if try(sub.ipv6, null) != null]
]),
# Management interfaces
[for int in try(local.device_config[device.name].interfaces.management, []) : {
device = device.name
vrf = "management"
id = "mgmt${int.id}"
ipv6_address_autoconfig = try(int.ipv6.address_autoconfig, null)
ipv6_nd_default_route = try(int.ipv6.nd_default_route, null)
ipv6_forward = try(int.ipv6.forward, null)
ipv6_link_local_use_bia = try(int.ipv6.link_local_use_bia, null)
ipv6_address_use_link_local_only = try(int.ipv6.address_use_link_local_only, null)
ipv6_verify_unicast_source_reachable_via = try(int.ipv6.verify_unicast_source_reachable_via, null)
ipv6_address_link_local = try(int.ipv6.address_link_local, null)
ipv6_addresses = try(int.ipv6.addresses, [])
} if try(int.ipv6, null) != null],
)
])
ipv6_interfaces_by_device_vrf = {
for entry in local.ipv6_interfaces : "${entry.device}/${entry.vrf}" => entry...
}
}
resource "nxos_ipv6" "ipv6" {
for_each = { for device in local.devices : device.name => device
if try(local.device_config[device.name].system.ipv6_routing, null) != null ||
try(local.device_config[device.name].system.ipv6_access_list_match_local_traffic, null) != null ||
try(local.device_config[device.name].nd.drop_nd_fragments, null) != null ||
try(local.device_config[device.name].nd.queue_packets, null) != null ||
try(local.device_config[device.name].nd.allow_static_neighbor_outside_subnet, null) != null ||
try(local.device_config[device.name].nd.switch_packets, null) != null ||
length(try(local.device_config[device.name].vrfs, [])) > 0 ||
length(try(local.device_config[device.name].routing.ipv6_routes, [])) > 0 ||
length([for int in local.ipv6_interfaces : int if int.device == device.name]) > 0 }
device = each.key
access_list_match_local = try(local.device_config[each.key].system.ipv6_access_list_match_local_traffic, null) != null ? (try(local.device_config[each.key].system.ipv6_access_list_match_local_traffic) ? "enabled" : "disabled") : null
admin_state = try(local.device_config[each.key].system.ipv6_routing, null) != null ? (try(local.device_config[each.key].system.ipv6_routing) ? "enabled" : "disabled") : null
drop_nd_fragments = try(local.device_config[each.key].nd.drop_nd_fragments, null) != null ? (try(local.device_config[each.key].nd.drop_nd_fragments) ? "enabled" : "disabled") : null
queue_packets = try(local.device_config[each.key].nd.queue_packets, null) != null ? (try(local.device_config[each.key].nd.queue_packets) ? "enabled" : "disabled") : null
static_neighbor_outside_subnet = try(local.device_config[each.key].nd.allow_static_neighbor_outside_subnet, null) != null ? (try(local.device_config[each.key].nd.allow_static_neighbor_outside_subnet) ? "enabled" : "disabled") : null
switch_packets = try(local.device_config[each.key].nd.switch_packets, null)
vrfs = merge(
# "default" VRF
{
"default" = {
static_routes = length(try(local.ipv6_routes_by_device_vrf["${each.key}/default"], [])) > 0 ? { for route in try(local.ipv6_routes_by_device_vrf["${each.key}/default"], []) : route.route.prefix => {
preference = try(route.route.preference, null)
tag = try(route.route.tag, null)
next_hops = length(try(route.route.next_hops, [])) > 0 ? { for nh in try(route.route.next_hops, []) : "${try(nh.interface_type, null) != null ? "${local.intf_prefix_map[try(nh.interface_type)]}${try(nh.interface_id, "")}" : "unspecified"};${try(nh.address, "::")};${try(nh.vrf, "default")}" => {
object = try(nh.track, null)
preference = try(nh.preference, null)
tag = try(nh.tag, null)
name = try(nh.name, null)
} } : null
} } : null
interfaces = length(try(local.ipv6_interfaces_by_device_vrf["${each.key}/default"], [])) > 0 ? { for int in local.ipv6_interfaces_by_device_vrf["${each.key}/default"] : int.id => {
auto_configuration = int.ipv6_address_autoconfig != null ? (int.ipv6_address_autoconfig ? "enabled" : "disabled") : null
default_route = int.ipv6_nd_default_route != null ? (int.ipv6_nd_default_route ? "enabled" : "disabled") : null
forward = int.ipv6_forward != null ? (int.ipv6_forward ? "enabled" : "disabled") : null
link_local_address_use_bia = int.ipv6_link_local_use_bia != null ? (int.ipv6_link_local_use_bia ? "enabled" : "disabled") : null
use_link_local_address = int.ipv6_address_use_link_local_only != null ? (int.ipv6_address_use_link_local_only ? "enabled" : "disabled") : null
urpf = try(local.urpf_map[int.ipv6_verify_unicast_source_reachable_via], int.ipv6_verify_unicast_source_reachable_via)
link_local_address = int.ipv6_address_link_local
addresses = length(int.ipv6_addresses) > 0 ? { for addr in int.ipv6_addresses : addr.address => {
type = try(addr.type, null)
tag = try(addr.tag, null)
control = try(addr.eui64, false) ? "eui64" : null
preference = try(addr.route_preference, null)
} } : null
} } : null
}
},
# VRFs from configuration.vrfs[]
{ for vrf in try(local.device_config[each.key].vrfs, []) : vrf.name => {
static_routes = length(try(local.ipv6_routes_by_device_vrf["${each.key}/${vrf.name}"], [])) > 0 ? { for route in try(local.ipv6_routes_by_device_vrf["${each.key}/${vrf.name}"], []) : route.route.prefix => {
preference = try(route.route.preference, null)
tag = try(route.route.tag, null)
next_hops = length(try(route.route.next_hops, [])) > 0 ? { for nh in try(route.route.next_hops, []) : "${try(nh.interface_type, null) != null ? "${local.intf_prefix_map[try(nh.interface_type)]}${try(nh.interface_id, "")}" : "unspecified"};${try(nh.address, "::")};${try(nh.vrf, "default")}" => {
object = try(nh.track, null)
preference = try(nh.preference, null)
tag = try(nh.tag, null)
name = try(nh.name, null)
} } : null
} } : null
interfaces = length(try(local.ipv6_interfaces_by_device_vrf["${each.key}/${vrf.name}"], [])) > 0 ? { for int in local.ipv6_interfaces_by_device_vrf["${each.key}/${vrf.name}"] : int.id => {
auto_configuration = int.ipv6_address_autoconfig != null ? (int.ipv6_address_autoconfig ? "enabled" : "disabled") : null
default_route = int.ipv6_nd_default_route != null ? (int.ipv6_nd_default_route ? "enabled" : "disabled") : null
forward = int.ipv6_forward != null ? (int.ipv6_forward ? "enabled" : "disabled") : null
link_local_address_use_bia = int.ipv6_link_local_use_bia != null ? (int.ipv6_link_local_use_bia ? "enabled" : "disabled") : null
use_link_local_address = int.ipv6_address_use_link_local_only != null ? (int.ipv6_address_use_link_local_only ? "enabled" : "disabled") : null
urpf = try(local.urpf_map[int.ipv6_verify_unicast_source_reachable_via], int.ipv6_verify_unicast_source_reachable_via)
link_local_address = int.ipv6_address_link_local
addresses = length(int.ipv6_addresses) > 0 ? { for addr in int.ipv6_addresses : addr.address => {
type = try(addr.type, null)
tag = try(addr.tag, null)
control = try(addr.eui64, false) ? "eui64" : null
preference = try(addr.route_preference, null)
} } : null
} } : null
} }
)
depends_on = [
nxos_feature.feature,
nxos_loopback_interface.loopback_interface,
nxos_physical_interface.physical_interface,
nxos_port_channel_interface.port_channel_interface,
nxos_subinterface.subinterface,
nxos_svi_interface.svi_interface,
nxos_vrf.vrf,
]
}