Skip to content

Commit c3cdc6d

Browse files
committed
adding ability to skip inventory and switch profiles
1 parent a56f9a0 commit c3cdc6d

6 files changed

+41
-32
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ A Terraform module to configure ACI Switch Configuration.
3333
| Name | Description |
3434
|------|-------------|
3535
| <a name="output_fabric_inventory"></a> [fabric\_inventory](#output\_fabric\_inventory) | Fabric Membership Identifiers: Fabric => Inventory => Fabric Membership |
36-
| <a name="output_interface_profiles"></a> [interface\_profiles](#output\_interface\_profiles) | Interface Profile Identifiers<br> interfaces:<br> leaf\_interface\_profiles: Fabric => Access Policies => Interfaces => Leaf Interfaces => Profiles<br> spine\_interface\_profiles: Fabric => Access Policies => Interfaces => Spine Interfaces => Profiles |
3736
| <a name="output_static_node_mgmt_address"></a> [static\_node\_mgmt\_address](#output\_static\_node\_mgmt\_address) | Static Node Management addresses: Tenants: {mgmt} => Node Management Addresses => Static Node Management Addresses |
38-
| <a name="output_switches"></a> [switches](#output\_switches) | Switch Identifiers<br> switches:<br> leaf\_profiles: Fabric => Access Policies => Switches => Leaf Switches => Profiles<br> spine\_profiles: Fabric => Access Policies => Switches => Spine Switches => Profiles |
37+
| <a name="output_switches"></a> [switches](#output\_switches) | Interface Profile Identifiers<br> interfaces:<br> leaf\_interface\_profiles: Fabric => Access Policies => Interfaces => Leaf Interfaces => Profiles<br> spine\_interface\_profiles: Fabric => Access Policies => Interfaces => Spine Interfaces => Profiles<br> Switch Identifiers<br> switches:<br> leaf\_profiles: Fabric => Access Policies => Switches => Leaf Switches => Profiles<br> spine\_profiles: Fabric => Access Policies => Switches => Spine Switches => Profiles |
3938
| <a name="output_vpc_domains"></a> [vpc\_domains](#output\_vpc\_domains) | VPC Domain Identifiers: Fabric => Access Policies => Policies => Switch => Virtual Port Channel default |
4039
## Resources
4140

defaults.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defaults:
1818
switch_profiles:
1919
description: ''
2020
external_pool_id: 0
21+
fabric_membership: true
2122
inband_addressing:
2223
ipv4_address: ''
2324
ipv4_gateway: ''
@@ -49,6 +50,7 @@ defaults:
4950
pod_id: 1
5051
role: unspecified
5152
serial_number: ''
53+
switch_profile: true
5254
two_slot_leaf: false
5355
vpc_domains:
5456
domain_id: null # REQUIRED ID Between 1-1000

inventory.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GUI Location:
88
_______________________________________________________________________________________________________________________
99
*/
1010
resource "aci_rest_managed" "fabric_membership" {
11-
for_each = { for v in local.switch_profiles : "${v.pod_id}:${v.node_id}" => v }
11+
for_each = { for v in local.switch_profiles : "${v.pod_id}:${v.node_id}" => v if v.fabric_membership == true }
1212
dn = "uni/controller/nodeidentpol/nodep-${each.value.serial_number}"
1313
class_name = "fabricNodeIdentP"
1414
content = {

locals.tf

+4-12
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ locals {
1717
#__________________________________________________________
1818

1919
switch_profiles = {
20-
for k, v in lookup(var.switch, "switch_profiles", []) : v.node_id => {
21-
description = lookup(v, "description", local.sprofile.description)
22-
external_pool_id = lookup(v, "external_pool_id", local.sprofile.external_pool_id)
23-
inband_addressing = lookup(v, "inband_addressing", [])
20+
for k, v in lookup(var.switch, "switch_profiles", []) : v.node_id => merge(local.sprofile, v, {
21+
inband_addressing = lookup(v, "inband_addressing", {})
2422
interfaces = [
2523
for i in lookup(v, "interfaces", []) : {
2624
description = lookup(i, "description", local.sprofile.interfaces.description)
@@ -36,17 +34,11 @@ locals {
3634

3735
}
3836
]
39-
policy_group = lookup(v, "policy_group", local.sprofile.policy_group)
40-
monitoring_policy = lookup(v, "monitoring_policy", local.sprofile.monitoring_policy)
4137
name = v.name
4238
node_id = v.node_id
43-
node_type = lookup(v, "node_type", local.sprofile.node_type)
44-
ooband_addressing = lookup(v, "ooband_addressing", [])
45-
pod_id = lookup(v, "pod_id", local.sprofile.pod_id)
46-
role = lookup(v, "role", local.sprofile.role)
39+
ooband_addressing = lookup(v, "ooband_addressing", {})
4740
serial_number = v.serial_number
48-
two_slot_leaf = lookup(v, "two_slot_leaf", local.sprofile.two_slot_leaf)
49-
}
41+
})
5042
}
5143

5244
interface_selectors = {

outputs.tf

+24-8
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,28 @@ output "fabric_inventory" {
1515

1616
/*_____________________________________________________________________________________________________________________
1717
18-
Interface Profiles — Outputs
18+
Interface Selectors — Outputs
1919
_______________________________________________________________________________________________________________________
2020
*/
21-
output "interface_profiles" {
21+
output "interface_selectors" {
2222
description = <<EOF
2323
Interface Profile Identifiers
2424
interfaces:
25-
leaf_interface_profiles: Fabric => Access Policies => Interfaces => Leaf Interfaces => Profiles
26-
spine_interface_profiles: Fabric => Access Policies => Interfaces => Spine Interfaces => Profiles
25+
Fabric => Access Policies => Interfaces => Leaf Interfaces => Profiles => Selectors
26+
Fabric => Access Policies => Interfaces => Spine Interfaces => Profiles => Selectors
2727
EOF
2828
value = {
29-
leaf_interface_profiles = {
30-
for v in sort(keys(aci_leaf_profile.map)) : v => aci_leaf_profile.map[v].id
29+
leaf_interface_selectors = {
30+
for v in sort(keys(aci_access_port_selector.map)) : v => {
31+
dn = aci_access_port_selector.map[v].id
32+
policy_group = aci_access_port_selector.map[v].relation_infra_rs_acc_base_grp
33+
}
3134
}
32-
spine_interface_profiles = {
33-
for v in sort(keys(aci_spine_profile.map)) : v => aci_spine_profile.map[v].id
35+
spine_interface_selectors = {
36+
for v in sort(keys(aci_rest_managed.spine_interface_policy_group)) : v => {
37+
dn = aci_rest_managed.spine_interface_policy_group[v].id
38+
policy_group = aci_rest_managed.spine_interface_policy_group[v].content.tDn
39+
}
3440
}
3541
}
3642
}
@@ -52,15 +58,25 @@ ________________________________________________________________________________
5258
*/
5359
output "switches" {
5460
description = <<EOF
61+
Interface Profile Identifiers
62+
interfaces:
63+
leaf_interface_profiles: Fabric => Access Policies => Interfaces => Leaf Interfaces => Profiles
64+
spine_interface_profiles: Fabric => Access Policies => Interfaces => Spine Interfaces => Profiles
5565
Switch Identifiers
5666
switches:
5767
leaf_profiles: Fabric => Access Policies => Switches => Leaf Switches => Profiles
5868
spine_profiles: Fabric => Access Policies => Switches => Spine Switches => Profiles
5969
EOF
6070
value = {
71+
leaf_interface_profiles = {
72+
for v in sort(keys(aci_leaf_interface_profile.map)) : v => aci_leaf_interface_profile.map[v].id
73+
}
6174
leaf_profiles = {
6275
for v in sort(keys(aci_leaf_profile.map)) : v => aci_leaf_profile.map[v].id
6376
}
77+
spine_interface_profiles = {
78+
for v in sort(keys(aci_spine_interface_profile.map)) : v => aci_spine_interface_profile.map[v].id
79+
}
6480
spine_profiles = {
6581
for v in sort(keys(aci_spine_profile.map)) : v => aci_spine_profile.map[v].id
6682
}

switch_profiles.tf

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ________________________________________________________________________________
2626
*/
2727
resource "aci_leaf_profile" "map" {
2828
depends_on = [aci_leaf_interface_profile.map]
29-
for_each = { for k, v in local.switch_profiles : k => v if v.node_type != "spine" }
29+
for_each = { for k, v in local.switch_profiles : k => v if v.node_type != "spine" && v.switch_profile == true }
3030
description = each.value.description
3131
name = "${local.npfx.leaf.switch_profiles}${each.value.name}${local.nsfx.leaf.switch_profiles}"
3232
relation_infra_rs_acc_port_p = [aci_leaf_interface_profile.map[each.key].id]
@@ -48,7 +48,7 @@ resource "aci_leaf_selector" "map" {
4848
aci_leaf_profile.map,
4949
]
5050
for_each = {
51-
for k, v in local.switch_profiles : k => v if v.node_type != "spine"
51+
for k, v in local.switch_profiles : k => v if v.node_type != "spine" && v.switch_profile == true
5252
}
5353
description = each.value.description
5454
leaf_profile_dn = aci_leaf_profile.map[each.key].id
@@ -61,7 +61,7 @@ resource "aci_node_block" "leaf_profile_blocks" {
6161
depends_on = [
6262
aci_leaf_selector.map
6363
]
64-
for_each = { for k, v in local.switch_profiles : k => v if v.node_type != "spine" }
64+
for_each = { for k, v in local.switch_profiles : k => v if v.node_type != "spine" && v.switch_profile == true }
6565
description = each.value.description
6666
from_ = each.value.node_id
6767
name = "blk${each.value.node_id}-${each.value.node_id}"
@@ -99,7 +99,7 @@ resource "aci_spine_profile" "map" {
9999
depends_on = [
100100
aci_spine_interface_profile.map
101101
]
102-
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" }
102+
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" && v.switch_profile == true }
103103
description = each.value.description
104104
name = "${local.npfx.spine.switch_profiles}${each.value.name}${local.nsfx.spine.switch_profiles}"
105105
relation_infra_rs_sp_acc_port_p = [
@@ -121,7 +121,7 @@ resource "aci_spine_switch_association" "map" {
121121
depends_on = [
122122
aci_spine_profile.map,
123123
]
124-
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" }
124+
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" && v.switch_profile == true }
125125
spine_profile_dn = aci_spine_profile.map[each.key].id
126126
description = each.value.description
127127
name = each.value.name
@@ -144,7 +144,7 @@ resource "aci_rest_managed" "spine_profile_node_blocks" {
144144
aci_spine_profile.map,
145145
aci_spine_switch_association.map
146146
]
147-
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" }
147+
for_each = { for k, v in local.switch_profiles : k => v if v.node_type == "spine" && v.switch_profile == true }
148148
dn = "${aci_spine_profile.map[each.key].id}/spines-${each.value.name}-typ-range/nodeblk-blk${each.key}-${each.key}"
149149
class_name = "infraNodeBlk"
150150
content = {
@@ -197,7 +197,7 @@ resource "aci_access_port_block" "leaf_port_blocks" {
197197
aci_leaf_interface_profile.map,
198198
aci_access_port_selector.map
199199
]
200-
for_each = { for k, v in local.interface_selectors : k => v if v.sub_port == "" && v.node_type != "spine" }
200+
for_each = { for k, v in local.interface_selectors : k => v if v.sub_port == false && v.node_type != "spine" }
201201
access_port_selector_dn = aci_access_port_selector.map[each.key].id
202202
description = each.value.interface_description
203203
from_card = each.value.module
@@ -222,7 +222,7 @@ resource "aci_access_sub_port_block" "leaf_port_subblocks" {
222222
aci_leaf_interface_profile.map,
223223
aci_access_port_selector.map
224224
]
225-
for_each = { for k, v in local.interface_selectors : k => v if v.sub_port != "" && v.node_type != "spine" }
225+
for_each = { for k, v in local.interface_selectors : k => v if v.sub_port == true && v.node_type != "spine" }
226226
access_port_selector_dn = aci_access_port_selector.map[each.key].id
227227
description = each.value.interface_description
228228
from_card = each.value.module
@@ -299,7 +299,7 @@ ________________________________________________________________________________
299299
*/
300300
resource "aci_static_node_mgmt_address" "map" {
301301
depends_on = [aci_rest_managed.fabric_membership]
302-
for_each = local.static_node_mgmt_addresses
302+
for_each = { for k, v in local.static_node_mgmt_addresses : k => v if length(v.ipv4_address) > 0 || length(v.ipv6_address) > 0 }
303303
addr = each.value.ipv4_address
304304
# description = each.value.description
305305
gw = each.value.ipv4_gateway

0 commit comments

Comments
 (0)