-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfmc_devices.tf
334 lines (296 loc) · 12 KB
/
fmc_devices.tf
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
###
# DEVICE
###
locals {
res_devices = flatten([
for domains in local.domains : [
for object in try(domains.devices.devices, []) : object if !contains(local.data_devices, object.name)
]
])
}
resource "fmc_devices" "device" {
for_each = { for device in local.res_devices : device.name => device }
# Mandatory
name = each.value.name
hostname = each.value.host
regkey = each.value.registration_key
access_policy {
id = local.map_accesspolicies[each.value.access_policy].id
}
# Optional
license_caps = try(each.value.licenses)
nat_id = try(each.value.nat_id, local.defaults.fmc.domains.devices.devices.nat_id, null)
performance_tier = try(each.value.performance_tier, local.defaults.fmc.domains.devices.devices.performance_tier, null)
lifecycle {
ignore_changes = [regkey, access_policy]
}
}
###
# Cluster
###
locals {
res_clusters = flatten([
for domains in local.domains : [
for cluster in try(domains.devices.clusters, []) : {
name = cluster.name
ccl_prefix = cluster.ccl_prefix
vni_prefix = cluster.vni_prefix
ccl_interface = cluster.ccl_interface
devices = [for dev in cluster.devices : {
name = dev.name
ccl_ip = dev.ccl_ip
control_node = try(dev.control_node, false)
idx = index(cluster.devices, dev) + 1
}
]
} if(!contains(local.data_clusters, cluster.name))
]
])
}
resource "fmc_device_cluster" "cluster" {
for_each = { for cluster in local.res_clusters : cluster.name => cluster }
# Mandatory
name = each.value.name
dynamic "control_device" {
for_each = { for dev in each.value.devices : dev.name => dev if(try(dev.control_node, false)) == true }
content {
cluster_node_bootstrap {
priority = try(control_device.value.priority, 1)
cclip = control_device.value.ccl_ip
}
device_details {
id = local.map_devices[control_device.value.name].id
name = control_device.value.name
}
}
}
common_bootstrap {
ccl_interface {
id = data.fmc_device_physical_interfaces.physical_interface["${each.value.devices[0].name}/${each.value.ccl_interface}"].id
name = data.fmc_device_physical_interfaces.physical_interface["${each.value.devices[0].name}/${each.value.ccl_interface}"].name
}
ccl_network = each.value.ccl_prefix
vni_network = each.value.vni_prefix
}
dynamic "data_devices" {
for_each = { for dev in each.value.devices : dev.name => dev if(try(dev.control_node, false)) == false }
content {
cluster_node_bootstrap {
priority = try(data_devices.value.priority, data_devices.value.idx)
cclip = data_devices.value.ccl_ip
}
device_details {
id = local.map_devices[data_devices.value.name].id
name = data_devices.value.name
}
}
}
depends_on = [
fmc_devices.device
]
}
###
# PHYSICAL INTERFACE Standalone/Cluster
###
resource "fmc_device_physical_interfaces" "physical_interface" {
for_each = { for physicalinterface in local.map_interfaces : physicalinterface.key => physicalinterface if physicalinterface.resource }
# Mandatory
name = each.value.data.interface
device_id = each.value.device_id
physical_interface_id = data.fmc_device_physical_interfaces.physical_interface[each.value.key].id
# Optional
if_name = try(each.value.data.name, null)
security_zone_id = try(local.map_securityzones[each.value.data.security_zone].id, null)
enabled = try(each.value.data.enabled, local.defaults.fmc.domains.devices.devices.physical_interfaces.enabled)
mtu = try(each.value.data.mtu, null)
mode = try(each.value.data.mode, local.defaults.fmc.domains.devices.devices.physical_interfaces.mode)
ipv4_static_address = try(each.value.data.ipv4_static_address, null)
ipv4_static_netmask = try(each.value.data.ipv4_static_netmask, null)
ipv4_dhcp_enabled = try(each.value.data.ipv4_dhcp, null)
ipv4_dhcp_route_metric = try(each.value.data.ipv4_dhcp_route_metric, null)
ipv6_address = try(each.value.data.ipv6_address, null)
ipv6_prefix = try(each.value.data.ipv6_prefix, null)
ipv6_enforce_eui = try(each.value.data.ipv6_enforce_eui64, null)
description = try(each.value.data.description, local.defaults.fmc.domains.devices.devices.physical_interfaces.description, null)
depends_on = [
data.fmc_device_physical_interfaces.physical_interface,
fmc_device_cluster.cluster
]
lifecycle {
ignore_changes = [
physical_interface_id
]
}
}
###
# SUBINTERFACE Standalone/Cluster
###
locals {
res_sub_interface = flatten([
for domain in local.domains : [
for device in try(domain.devices.devices, []) : [
for physicalinterface in try(device.physical_interfaces, []) : [
for subinterface in try(physicalinterface.subinterfaces, []) : {
key = "${device.name}/${physicalinterface.interface}/${subinterface.id}"
phyinterface = physicalinterface.interface
device_id = local.map_devices[device.name].id
device_name = device.name
data = subinterface
} if !contains(local.data_sub_interfces_list, "${device.name}/${physicalinterface.interface}/${subinterface.id}")
]
]
]
])
}
resource "fmc_device_subinterfaces" "sub_interfaces" {
for_each = { for subinterface in local.res_sub_interface : subinterface.key => subinterface }
# Mandatory
name = each.value.phyinterface
device_id = each.value.device_id
subinterface_id = each.value.data.id
# Optional
ifname = try(each.value.data.name, null)
vlan_id = try(each.value.data.vlan, null)
enable_ipv6 = try(each.value.data.ipv6, null)
enabled = try(each.value.data.enabled, null)
ipv4_dhcp_enabled = try(each.value.data.ipv4_dhcp, null)
ipv4_dhcp_route_metric = try(each.value.data.ipv4_dhcp_route_metric, null)
ipv4_static_address = try(each.value.data.ipv4_static_address, null)
ipv4_static_netmask = try(each.value.data.ipv4_static_netmask, null)
ipv6_address = try(each.value.data.ipv6_address, null)
ipv6_enforce_eui = try(each.value.data.ipv6_enforce_eui, null)
ipv6_prefix = try(each.value.data.ipv6_prefix, null)
management_only = try(each.value.data.management_only, null)
mode = try(each.value.data.mode, local.defaults.fmc.domains.devices.devices.physical_interfaces.subinterfaces.mode, null)
mtu = try(each.value.data.mtu, null)
priority = try(each.value.data.priority, null)
security_zone_id = try(local.map_securityzones[each.value.data.security_zone].id, null)
}
###
# VTEP
###
locals {
res_vtep_interfaces = flatten([
for domain in local.domains : [
for device in try(domain.devices.devices, []) : [
for physicalinterface in try(device.physical_interfaces, []) : [
for vtep in try(physicalinterface.vteps, []) : {
key = "${device.name}/${physicalinterface.interface}/${vtep.encapsulation_port}"
device_id = local.map_devices[device.name].id
physicalinterface_id = data.fmc_device_physical_interfaces.physical_interface["${device.name}/${physicalinterface.interface}"].id
data = vtep
}
]
]
]
])
}
resource "fmc_device_vtep" "vtep" {
for_each = { for vtep in local.res_vtep_interfaces : vtep.key => vtep }
device_id = each.value.device_id
source_interface_id = each.value.physicalinterface_id
nve_vtep_id = 1 #It is fixed value
nve_enabled = each.value.data.nve_enabled
nve_destination_port = each.value.data.encapsulation_port
nve_encapsulation_type = each.value.data.encapsulation_type
depends_on = [
fmc_device_physical_interfaces.physical_interface,
data.fmc_device_physical_interfaces.physical_interface,
fmc_device_subinterfaces.sub_interfaces,
data.fmc_device_subinterfaces.sub_interfaces
]
}
###
# VNI
###
locals {
res_vni_interfaces = flatten([
for domain in local.domains : [
for device in try(domain.devices.devices, []) : [
for vni in try(device.vnis, []) : {
key = "${device.name}/${vni.name}/${vni.vni_id}"
device_id = local.map_devices[device.name].id
data = vni
} if !contains(local.data_vni_interfaces_list, "${device.name}/${vni.name}/${vni.vni_id}")
]
]
])
}
resource "fmc_device_vni" "vni" {
for_each = { for vni in local.res_vni_interfaces : vni.key => vni }
device_id = each.value.device_id
security_zone_id = try(local.map_securityzones[each.value.data.security_zone].id, null)
if_name = each.value.data.name
enabled = try(each.value.data.enabled, null)
description = try(each.value.data.description, local.defaults.fmc.domains.devices.devices.vnis.description, "VNI Interface")
priority = try(each.value.data.priority, null)
vnid = each.value.data.vni_id
segment_id = try(each.value.data.vni_segment_id, null)
multicast_groupaddress = try(each.value.data.multicast_group_address, null)
enable_proxy = try(each.value.data.vne_to_vtep_mapping, null)
ipv4 {
static {
address = try(each.value.data.ipv4_static_address, null)
netmask = try(each.value.data.ipv4_static_netmask, null)
}
dhcp {
enable_default_route_dhcp = try(each.value.data.ipv4_dhcp, false) ? each.value.data.ipv4_dhcp_default_route : null
dhcp_route_metric = try(each.value.data.ipv4_dhcp, false) ? each.value.data.ipv4_dhcp_route_metric : null
}
}
depends_on = [
fmc_device_physical_interfaces.physical_interface,
data.fmc_device_physical_interfaces.physical_interface,
fmc_device_subinterfaces.sub_interfaces,
data.fmc_device_subinterfaces.sub_interfaces
]
}
###
# IPV4 STATIC ROUTE
###
locals {
res_ipv4staticroutes = flatten([
for domain in local.domains : [
for device in try(domain.devices.devices, []) : [
for ipv4staticroute in try(device.ipv4_static_routes, []) : {
key = "${device.name}/${ipv4staticroute.name}"
device_id = local.map_devices[device.name].id
gateway_id = local.map_networkobjects[ipv4staticroute.gateway.object].id
gateway_type = local.map_networkobjects[ipv4staticroute.gateway.object].type
gateway_name = ipv4staticroute.gateway.object
interface_name = ipv4staticroute.interface
selected_networks = ipv4staticroute.selected_networks
}
]
]
])
}
resource "fmc_staticIPv4_route" "ipv4staticroute" {
for_each = { for ipv4staticroute in local.res_ipv4staticroutes : ipv4staticroute.key => ipv4staticroute }
# Mandatory
device_id = each.value.device_id
interface_name = each.value.interface_name
metric_value = try(each.value.metric_value, local.defaults.fmc.domains.devices.devices.ipv4_static_routes.metric_value)
gateway {
object {
id = each.value.gateway_id
type = each.value.gateway_type
name = each.value.gateway_name
}
}
dynamic "selected_networks" {
for_each = { for obj in each.value.selected_networks : obj => obj }
content {
id = try(local.map_networkobjects[selected_networks.value].id, null)
type = try(local.map_networkobjects[selected_networks.value].type, null)
}
}
# Optional
is_tunneled = try(each.value.tunneled, local.defaults.fmc.domains.devices.devices.ipv4_static_routes.tunneled, null)
depends_on = [
fmc_device_physical_interfaces.physical_interface,
data.fmc_device_physical_interfaces.physical_interface,
fmc_device_subinterfaces.sub_interfaces,
data.fmc_device_subinterfaces.sub_interfaces
]
}