-
Notifications
You must be signed in to change notification settings - Fork 0
/
design___rack-types.tf
64 lines (60 loc) · 2.62 KB
/
design___rack-types.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
#################################################
### Rack Types
variable "rack_types_file_path" {
description = "Path to the YAML file - rack types"
default = "/config/rack_types.yaml"
}
locals {
rack_types_file_yaml = fileexists("${path.module}${var.rack_types_file_path}") ? file("${path.module}${var.rack_types_file_path}") : ""
rack_types_data = try(yamldecode(local.rack_types_file_yaml)["rack_types"], {})
rack_types = can(local.rack_types_data) && length(keys(coalesce(local.rack_types_data, {}))) > 0 ? local.rack_types_data : {}
}
output "debug_rack_types" { value = var.debug ? local.rack_types : null }
#################################################
#################################################
### Get Maping Leaf "LogicalDevice"=>"ID"
locals {
logical_devices_for_rack_types = distinct(flatten([
for rack_name, rack_config in local.rack_types : [
for leaf_config in rack_config.leaf_switches : leaf_config.logical_device
]
]))
}
data "apstra_logical_device" "selected_for_rack_types" {
for_each = { for device in local.logical_devices_for_rack_types : device => device }
name = each.value
}
locals {
logical_devices_for_rack_types_ids = {
for key, value in data.apstra_logical_device.selected_for_rack_types : key => value.id
}
}
output "debug_logical_devices_for_rack_types_ids" { value = var.debug ? local.logical_devices_for_rack_types_ids : null }
#################################################
#################################################
## Create Racks
resource "apstra_rack_type" "all" {
for_each = can(local.rack_types) ? local.rack_types : {}
name = each.value.name
description = each.value.description
fabric_connectivity_design = each.value.fabric_connectivity_design
leaf_switches = {
leaf_switch = {
logical_device_id = local.logical_devices_for_rack_types_ids[each.value.leaf_switches.0.logical_device]
spine_link_count = each.value.leaf_switches.0.spine_link_count
spine_link_speed = each.value.leaf_switches.0.spine_link_speed
redundancy_protocol = each.value.leaf_switches.0.redundancy_protocol
}
}
}
#################################################
#################################################
### Collect all Rack Type IDs
data "apstra_rack_types" "all" {}
# Loop over Rack Type IDs, collect full details of each Rack Type
data "apstra_rack_type" "each" {
for_each = data.apstra_rack_types.all.ids
id = each.key
}
output "debug_apstra_rack_type" { value = var.debug ? data.apstra_rack_type.each : null }
#################################################