Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIC 4.x/5.x Interface shutdown Support #164

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ repos:
args: ["./modules/terraform-aci-interface-configuration"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-interface-configuration/examples/complete"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-interface-shutdown"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-interface-shutdown/examples/complete"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-interface-type"]
- id: terraform-docs-system
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Additional example repositories:
| <a name="module_aci_fabric_spine_switch_profile_auto"></a> [aci\_fabric\_spine\_switch\_profile\_auto](#module\_aci\_fabric\_spine\_switch\_profile\_auto) | ./modules/terraform-aci-fabric-spine-switch-profile | n/a |
| <a name="module_aci_fabric_spine_switch_profile_manual"></a> [aci\_fabric\_spine\_switch\_profile\_manual](#module\_aci\_fabric\_spine\_switch\_profile\_manual) | ./modules/terraform-aci-fabric-spine-switch-profile | n/a |
| <a name="module_aci_fabric_wide_settings"></a> [aci\_fabric\_wide\_settings](#module\_aci\_fabric\_wide\_settings) | ./modules/terraform-aci-fabric-wide-settings | n/a |
| <a name="module_aci_fex_interface_shutdown"></a> [aci\_fex\_interface\_shutdown](#module\_aci\_fex\_interface\_shutdown) | ./modules/terraform-aci-interface-shutdown | n/a |
| <a name="module_aci_filter"></a> [aci\_filter](#module\_aci\_filter) | ./modules/terraform-aci-filter | n/a |
| <a name="module_aci_firmware_group"></a> [aci\_firmware\_group](#module\_aci\_firmware\_group) | ./modules/terraform-aci-firmware-group | n/a |
| <a name="module_aci_forwarding_scale_policy"></a> [aci\_forwarding\_scale\_policy](#module\_aci\_forwarding\_scale\_policy) | ./modules/terraform-aci-forwarding-scale-policy | n/a |
Expand All @@ -232,6 +233,7 @@ Additional example repositories:
| <a name="module_aci_infra_dhcp_relay_policy"></a> [aci\_infra\_dhcp\_relay\_policy](#module\_aci\_infra\_dhcp\_relay\_policy) | ./modules/terraform-aci-infra-dhcp-relay-policy | n/a |
| <a name="module_aci_infra_dscp_translation_policy"></a> [aci\_infra\_dscp\_translation\_policy](#module\_aci\_infra\_dscp\_translation\_policy) | ./modules/terraform-aci-infra-dscp-translation-policy | n/a |
| <a name="module_aci_interface_configuration_fex"></a> [aci\_interface\_configuration\_fex](#module\_aci\_interface\_configuration\_fex) | ./modules/terraform-aci-interface-configuration | n/a |
| <a name="module_aci_interface_shutdown"></a> [aci\_interface\_shutdown](#module\_aci\_interface\_shutdown) | ./modules/terraform-aci-interface-shutdown | n/a |
| <a name="module_aci_interface_type"></a> [aci\_interface\_type](#module\_aci\_interface\_type) | ./modules/terraform-aci-interface-type | n/a |
| <a name="module_aci_ip_aging"></a> [aci\_ip\_aging](#module\_aci\_ip\_aging) | ./modules/terraform-aci-ip-aging | n/a |
| <a name="module_aci_ip_sla_policy"></a> [aci\_ip\_sla\_policy](#module\_aci\_ip\_sla\_policy) | ./modules/terraform-aci-ip-sla-policy | n/a |
Expand Down Expand Up @@ -310,6 +312,7 @@ Additional example repositories:
| <a name="module_aci_sr_mpls_l3out_interface_profile_manual"></a> [aci\_sr\_mpls\_l3out\_interface\_profile\_manual](#module\_aci\_sr\_mpls\_l3out\_interface\_profile\_manual) | ./modules/terraform-aci-l3out-interface-profile | n/a |
| <a name="module_aci_sr_mpls_l3out_node_profile_manual"></a> [aci\_sr\_mpls\_l3out\_node\_profile\_manual](#module\_aci\_sr\_mpls\_l3out\_node\_profile\_manual) | ./modules/terraform-aci-l3out-node-profile | n/a |
| <a name="module_aci_storm_control_policy"></a> [aci\_storm\_control\_policy](#module\_aci\_storm\_control\_policy) | ./modules/terraform-aci-storm-control-policy | n/a |
| <a name="module_aci_subinterface_shutdown"></a> [aci\_subinterface\_shutdown](#module\_aci\_subinterface\_shutdown) | ./modules/terraform-aci-interface-shutdown | n/a |
| <a name="module_aci_syslog_policy"></a> [aci\_syslog\_policy](#module\_aci\_syslog\_policy) | ./modules/terraform-aci-syslog-policy | n/a |
| <a name="module_aci_system_global_gipo"></a> [aci\_system\_global\_gipo](#module\_aci\_system\_global\_gipo) | ./modules/terraform-aci-system-global-gipo | n/a |
| <a name="module_aci_system_performance"></a> [aci\_system\_performance](#module\_aci\_system\_performance) | ./modules/terraform-aci-system-performance | n/a |
Expand Down
74 changes: 74 additions & 0 deletions aci_interface_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,77 @@ module "aci_spine_fabric_interface_configuration" {
shutdown = each.value.shutdown
role = each.value.role
}

locals {
interface_shutdown = flatten([
for node in local.nodes : [
for interface in try(node.interfaces, []) : {
key = format("%s/%s/%s", node.id, try(interface.module, local.defaults.apic.interface_policies.nodes.interfaces.module), interface.port)
node_id = node.id
module = try(interface.module, local.defaults.apic.interface_policies.nodes.interfaces.module)
port = interface.port
} if try(interface.shutdown, local.defaults.apic.interface_policies.nodes.interfaces.shutdown)
] if(try(local.apic.auto_generate_switch_pod_profiles, local.defaults.apic.auto_generate_switch_pod_profiles) || try(local.apic.auto_generate_access_leaf_switch_interface_profiles, local.defaults.apic.auto_generate_access_leaf_switch_interface_profiles) || try(local.apic.auto_generate_access_spine_switch_interface_profiles, local.defaults.apic.auto_generate_access_spine_switch_interface_profiles)) && try(local.apic.new_interface_configuration, local.defaults.apic.new_interface_configuration) == false
])
}

module "aci_interface_shutdown" {
source = "./modules/terraform-aci-interface-shutdown"

for_each = { for int in local.interface_shutdown : int.key => int if local.modules.aci_interface_shutdown && var.manage_interface_policies }
node_id = each.value.node_id
module = each.value.module
port = each.value.port
}

locals {
subinterface_shutdown = flatten([
for node in local.nodes : [
for interface in try(node.interfaces, []) : [
for subinterface in try(interface.sub_ports, []) : {
key = format("%s/%s/%s/%s", node.id, try(interface.module, local.defaults.apic.interface_policies.nodes.interfaces.module), interface.port, subinterface.port)
node_id = node.id
module = try(interface.module, local.defaults.apic.interface_policies.nodes.interfaces.module)
port = interface.port
sub_port = subinterface.port
} if try(subinterface.shutdown, local.defaults.apic.interface_policies.nodes.interfaces.sub_ports.shutdown)
]
] if(try(local.apic.auto_generate_switch_pod_profiles, local.defaults.apic.auto_generate_switch_pod_profiles) || try(local.apic.auto_generate_access_leaf_switch_interface_profiles, local.defaults.apic.auto_generate_access_leaf_switch_interface_profiles) || try(local.apic.auto_generate_access_spine_switch_interface_profiles, local.defaults.apic.auto_generate_access_spine_switch_interface_profiles)) && try(local.apic.new_interface_configuration, local.defaults.apic.new_interface_configuration) == false
])
}

module "aci_subinterface_shutdown" {
source = "./modules/terraform-aci-interface-shutdown"

for_each = { for int in local.subinterface_shutdown : int.key => int if local.modules.aci_interface_shutdown && var.manage_interface_policies }
node_id = each.value.node_id
module = each.value.module
port = each.value.port
sub_port = each.value.sub_port
}

locals {
fex_interface_shutdown = flatten([
for node in local.nodes : [
for fex in try(node.fexes, []) : [
for interface in try(fex.interfaces, []) : {
key = format("%s/%s/%s/%s", node.id, fex.id, try(interface.module, local.defaults.apic.interface_policies.nodes.fexes.interfaces.module), interface.port)
node_id = node.id
fex_id = fex.id
module = try(interface.module, local.defaults.apic.interface_policies.nodes.fexes.interfaces.module)
port = interface.port
} if try(interface.shutdown, local.defaults.apic.interface_policies.nodes.fexes.interfaces.shutdown)
]
] if(try(local.apic.auto_generate_switch_pod_profiles, local.defaults.apic.auto_generate_switch_pod_profiles) || try(local.apic.auto_generate_access_leaf_switch_interface_profiles, local.defaults.apic.auto_generate_access_leaf_switch_interface_profiles) || try(local.apic.auto_generate_access_spine_switch_interface_profiles, local.defaults.apic.auto_generate_access_spine_switch_interface_profiles)) && try(local.apic.new_interface_configuration, local.defaults.apic.new_interface_configuration) == false
])
}

module "aci_fex_interface_shutdown" {
source = "./modules/terraform-aci-interface-shutdown"

for_each = { for int in local.fex_interface_shutdown : int.key => int if local.modules.aci_interface_shutdown && var.manage_interface_policies }
node_id = each.value.node_id
fex_id = each.value.fex_id
module = each.value.module
port = each.value.port
}
1 change: 1 addition & 0 deletions defaults/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ defaults:
fexes:
interfaces:
from_module: 1
module: 1
shutdown: false

tenants:
Expand Down
1 change: 1 addition & 0 deletions defaults/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ modules:
aci_infra_dhcp_relay_policy: true
aci_infra_dscp_translation_policy: true
aci_interface_configuration: true
aci_interface_shutdown: true
aci_interface_type: true
aci_ip_aging: true
aci_ip_sla_policy: true
Expand Down
34 changes: 34 additions & 0 deletions modules/terraform-aci-interface-shutdown/.terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '>= 0.14.0'

formatter: markdown table

content: |-
# Terraform ACI Interface Shutdown Module

Manages Interface Shutdown

Location in GUI:
`Fabric` » `Inventory` » `Pod XXX` » `Node XXX` » `Interface`

## Examples

```hcl
{{ include "./examples/complete/main.tf" }}
```

{{ .Requirements }}

{{ .Providers }}

{{ .Inputs }}

{{ .Outputs }}

{{ .Resources }}

output:
file: README.md
mode: replace

sort:
enabled: false
58 changes: 58 additions & 0 deletions modules/terraform-aci-interface-shutdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- BEGIN_TF_DOCS -->
# Terraform ACI Interface Shutdown Module

Manages Interface Shutdown

Location in GUI:
`Fabric` » `Inventory` » `Pod XXX` » `Node XXX` » `Interface`

## Examples

```hcl
module "aci_interface_shutdown" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-shutdown"
version = ">= 0.9.2"

pod_id = 1
node_id = 101
module = 1
port = 1
}
```

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
| <a name="requirement_aci"></a> [aci](#requirement\_aci) | >= 2.0.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aci"></a> [aci](#provider\_aci) | >= 2.0.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_pod_id"></a> [pod\_id](#input\_pod\_id) | Interface Pod ID. Minimum value: `1`. Maximum value: `255`. | `number` | `1` | no |
| <a name="input_node_id"></a> [node\_id](#input\_node\_id) | Interface Node ID. Minimum value: `101`. Maximum value: `4000`. | `number` | n/a | yes |
| <a name="input_module"></a> [module](#input\_module) | Interface Module. Minimum value: `1`. Maximum value: `255`. | `number` | `1` | no |
| <a name="input_port"></a> [port](#input\_port) | Interface Port. Minimum value: `1`. Maximum value: `127`. | `number` | n/a | yes |
| <a name="input_sub_port"></a> [sub\_port](#input\_sub\_port) | Interface Sub-Port. Allowed values: 1-64. `0` meaning no Sub-Port. | `number` | `0` | no |
| <a name="input_fex_id"></a> [fex\_id](#input\_fex\_id) | Interface FEX ID. Allowed values: 101-199. `0` meaning no FEX. | `number` | `0` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_dn"></a> [dn](#output\_dn) | Distinguished name of `fabricRsOosPath` object. |

## Resources

| Name | Type |
|------|------|
| [aci_rest_managed.fabricRsOosPath](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '>= 0.14.0'

formatter: markdown table

content: |-
# Interface Shutdown Example

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example will create resources. Resources can be destroyed with `terraform destroy`.

```hcl
{{ include "./main.tf" }}
```

output:
file: README.md
mode: replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- BEGIN_TF_DOCS -->
# Interface Shutdown Example

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example will create resources. Resources can be destroyed with `terraform destroy`.

```hcl
module "aci_interface_shutdown" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-shutdown"
version = ">= 0.9.2"

pod_id = 1
node_id = 101
module = 1
port = 1
}
```
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "aci_interface_shutdown" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-shutdown"
version = ">= 0.9.2"

pod_id = 1
node_id = 101
module = 1
port = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

terraform {
required_version = ">= 1.0.0"

required_providers {
aci = {
source = "CiscoDevNet/aci"
version = ">= 2.0.0"
}
}
}
7 changes: 7 additions & 0 deletions modules/terraform-aci-interface-shutdown/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aci_rest_managed" "fabricRsOosPath" {
dn = var.fex_id != 0 ? "uni/fabric/outofsvc/rsoosPath-[topology/pod-${var.pod_id}/paths-${var.node_id}/extpaths-${var.fex_id}/pathep-[eth${var.module}/${var.port}]]" : (var.sub_port != 0 ? "uni/fabric/outofsvc/rsoosPath-[topology/pod-${var.pod_id}/paths-${var.node_id}/pathep-[eth${var.module}/${var.port}/${var.sub_port}]]" : "uni/fabric/outofsvc/rsoosPath-[topology/pod-${var.pod_id}/paths-${var.node_id}/pathep-[eth${var.module}/${var.port}]]")
class_name = "fabricRsOosPath"
content = {
lc = "blacklist"
}
}
4 changes: 4 additions & 0 deletions modules/terraform-aci-interface-shutdown/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "dn" {
value = aci_rest_managed.fabricRsOosPath.id
description = "Distinguished name of `fabricRsOosPath` object."
}
63 changes: 63 additions & 0 deletions modules/terraform-aci-interface-shutdown/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
variable "pod_id" {
description = "Interface Pod ID. Minimum value: `1`. Maximum value: `255`."
type = number
default = 1

validation {
condition = var.pod_id >= 1 && var.pod_id <= 255
error_message = "Minimum value: `1`. Maximum value: `255`."
}
}

variable "node_id" {
description = "Interface Node ID. Minimum value: `101`. Maximum value: `4000`."
type = number

validation {
condition = var.node_id >= 101 && var.node_id <= 4000
error_message = "Minimum value: `101`. Maximum value: `4000`."
}
}

variable "module" {
description = "Interface Module. Minimum value: `1`. Maximum value: `255`."
type = number
default = 1

validation {
condition = var.module >= 1 && var.module <= 255
error_message = "Allowed values: 1-255."
}
}

variable "port" {
description = "Interface Port. Minimum value: `1`. Maximum value: `127`."
type = number

validation {
condition = var.port >= 1 && var.port <= 127
error_message = "Minimum value: `1`. Maximum value: `127`."
}
}

variable "sub_port" {
description = "Interface Sub-Port. Allowed values: 1-64. `0` meaning no Sub-Port."
type = number
default = 0

validation {
condition = var.sub_port >= 0 && var.sub_port <= 64
error_message = "Allowed values: 0, 1-64."
}
}

variable "fex_id" {
description = "Interface FEX ID. Allowed values: 101-199. `0` meaning no FEX."
type = number
default = 0

validation {
condition = var.fex_id == 0 || (var.fex_id >= 101 && var.fex_id <= 199)
error_message = "Allowed values: 0, 101-199."
}
}
11 changes: 11 additions & 0 deletions modules/terraform-aci-interface-shutdown/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

terraform {
required_version = ">= 1.0.0"

required_providers {
aci = {
source = "CiscoDevNet/aci"
version = ">= 2.0.0"
}
}
}