-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathiosxe_vrrp_v2.tf
More file actions
150 lines (143 loc) · 8.2 KB
/
Copy pathiosxe_vrrp_v2.tf
File metadata and controls
150 lines (143 loc) · 8.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
locals {
interfaces_vrrp_v2 = flatten([
for device in local.devices : concat(
[
for int in try(local.device_config[device.name].interfaces.ethernets, []) : [
for vrrp in try(int.vrrp_v2, []) : {
key = format("%s/%s%s/vrrp_v2/%s", device.name, try(int.type, "GigabitEthernet"), trimprefix(int.id, "$string "), vrrp.group_id)
device = device.name
type = try(int.type, "GigabitEthernet")
name = trimprefix(int.id, "$string ")
managed = try(int.managed, true)
group_id = vrrp.group_id
ip_primary_address = try(vrrp.ip_primary_address, null)
ip_secondary_addresses = try(length(vrrp.ip_secondary_addresses) == 0, true) ? null : [for addr in vrrp.ip_secondary_addresses : { address = addr }]
priority = try(vrrp.priority, null)
preempt = try(vrrp.preempt, null)
preempt_delay_minimum = try(vrrp.preempt_delay_minimum, null)
timers_advertise_interval = try(vrrp.timers_advertise_interval, null)
authentication_text = try(vrrp.authentication_text, null)
description = try(vrrp.description, null)
tracks = try(length(vrrp.tracks) == 0, true) ? null : [for t in vrrp.tracks : { object_id = t.object_id, decrement = try(t.decrement, null) }]
shutdown = try(vrrp.shutdown, null)
}
]
],
[
for int in try(local.device_config[device.name].interfaces.vlans, []) : [
for vrrp in try(int.vrrp_v2, []) : {
key = format("%s/Vlan%s/vrrp_v2/%s", device.name, int.id, vrrp.group_id)
device = device.name
type = "Vlan"
name = tostring(int.id)
managed = true
group_id = vrrp.group_id
ip_primary_address = try(vrrp.ip_primary_address, null)
ip_secondary_addresses = try(length(vrrp.ip_secondary_addresses) == 0, true) ? null : [for addr in vrrp.ip_secondary_addresses : { address = addr }]
priority = try(vrrp.priority, null)
preempt = try(vrrp.preempt, null)
preempt_delay_minimum = try(vrrp.preempt_delay_minimum, null)
timers_advertise_interval = try(vrrp.timers_advertise_interval, null)
authentication_text = try(vrrp.authentication_text, null)
description = try(vrrp.description, null)
tracks = try(length(vrrp.tracks) == 0, true) ? null : [for t in vrrp.tracks : { object_id = t.object_id, decrement = try(t.decrement, null) }]
shutdown = try(vrrp.shutdown, null)
}
]
],
[
for int in try(local.device_config[device.name].interfaces.port_channels, []) : [
for vrrp in try(int.vrrp_v2, []) : {
key = format("%s/Port-channel%s/vrrp_v2/%s", device.name, trimprefix(tostring(int.id), "$string "), vrrp.group_id)
device = device.name
type = "Port-channel"
name = trimprefix(tostring(int.id), "$string ")
managed = true
group_id = vrrp.group_id
ip_primary_address = try(vrrp.ip_primary_address, null)
ip_secondary_addresses = try(length(vrrp.ip_secondary_addresses) == 0, true) ? null : [for addr in vrrp.ip_secondary_addresses : { address = addr }]
priority = try(vrrp.priority, null)
preempt = try(vrrp.preempt, null)
preempt_delay_minimum = try(vrrp.preempt_delay_minimum, null)
timers_advertise_interval = try(vrrp.timers_advertise_interval, null)
authentication_text = try(vrrp.authentication_text, null)
description = try(vrrp.description, null)
tracks = try(length(vrrp.tracks) == 0, true) ? null : [for t in vrrp.tracks : { object_id = t.object_id, decrement = try(t.decrement, null) }]
shutdown = try(vrrp.shutdown, null)
}
]
],
[
for int in try(local.device_config[device.name].interfaces.port_channels, []) : [
for sub in try(int.subinterfaces, []) : [
for vrrp in try(sub.vrrp_v2, []) : {
key = format("%s/Port-channel%s/vrrp_v2/%s", device.name, trimprefix(sub.id, "$string "), vrrp.group_id)
device = device.name
type = "Port-channel-subinterface/Port-channel"
name = trimprefix(sub.id, "$string ")
managed = true
group_id = vrrp.group_id
ip_primary_address = try(vrrp.ip_primary_address, null)
ip_secondary_addresses = try(length(vrrp.ip_secondary_addresses) == 0, true) ? null : [for addr in vrrp.ip_secondary_addresses : { address = addr }]
priority = try(vrrp.priority, null)
preempt = try(vrrp.preempt, null)
preempt_delay_minimum = try(vrrp.preempt_delay_minimum, null)
timers_advertise_interval = try(vrrp.timers_advertise_interval, null)
authentication_text = try(vrrp.authentication_text, null)
description = try(vrrp.description, null)
tracks = try(length(vrrp.tracks) == 0, true) ? null : [for t in vrrp.tracks : { object_id = t.object_id, decrement = try(t.decrement, null) }]
shutdown = try(vrrp.shutdown, null)
}
]
]
]
)
])
}
resource "iosxe_interface_vrrp_v2" "vrrp_v2" {
for_each = { for v in local.interfaces_vrrp_v2 : v.key => v if v.managed }
device = each.value.device
type = each.value.type
name = each.value.name
group_id = each.value.group_id
ip_primary_address = each.value.ip_primary_address
ip_secondary_addresses = each.value.ip_secondary_addresses
priority = each.value.priority
preempt = each.value.preempt
preempt_delay_minimum = each.value.preempt_delay_minimum
timers_advertise_interval = each.value.timers_advertise_interval
authentication_text = each.value.authentication_text
description = each.value.description
tracks = each.value.tracks
shutdown = each.value.shutdown
depends_on = [
iosxe_interface_ethernet.ethernet,
iosxe_interface_ethernet.ethernet_sub,
iosxe_interface_vlan.vlan,
iosxe_interface_port_channel.port_channel,
iosxe_interface_port_channel_subinterface.port_channel_subinterface
]
}
resource "iosxe_interface_vrrp_v2" "vrrp_v2_unmanaged" {
for_each = { for v in local.interfaces_vrrp_v2 : v.key => v if !v.managed }
device = each.value.device
type = each.value.type
name = each.value.name
group_id = each.value.group_id
ip_primary_address = each.value.ip_primary_address
ip_secondary_addresses = each.value.ip_secondary_addresses
priority = each.value.priority
preempt = each.value.preempt
preempt_delay_minimum = each.value.preempt_delay_minimum
timers_advertise_interval = each.value.timers_advertise_interval
authentication_text = each.value.authentication_text
description = each.value.description
tracks = each.value.tracks
shutdown = each.value.shutdown
depends_on = [
iosxe_interface_ethernet.ethernet_unmanaged
]
lifecycle {
ignore_changes = all
}
}