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 2 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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ Additional example repositories:

| Name | Version |
|------|---------|
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.3.0 |
| <a name="provider_utils"></a> [utils](#provider\_utils) | >= 0.2.5 |
| <a name="provider_local"></a> [local](#provider\_local) | 2.5.2 |
| <a name="provider_utils"></a> [utils](#provider\_utils) | 0.2.6 |

## Resources

Expand Down 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_state"></a> [aci\_fex\_interface\_state](#module\_aci\_fex\_interface\_state) | ./modules/terraform-aci-interface-state | 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_state"></a> [aci\_interface\_state](#module\_aci\_interface\_state) | ./modules/terraform-aci-interface-state | 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
55 changes: 55 additions & 0 deletions aci_interface_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,58 @@ module "aci_spine_fabric_interface_configuration" {
shutdown = each.value.shutdown
role = each.value.role
}

locals {
interface_state = 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
shutdown = 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)) && (length(var.managed_interface_policies_nodes) == 0 || contains(var.managed_interface_policies_nodes, node.id)) && try(local.apic.new_interface_configuration, local.defaults.apic.new_interface_configuration) == false
])
}

module "aci_interface_state" {
source = "./modules/terraform-aci-interface-state"

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

locals {
fex_interface_state = 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, "1", interface.port)
node_id = node.id
module = fex.id
port = interface.port
shutdown = 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)) && (length(var.managed_interface_policies_nodes) == 0 || contains(var.managed_interface_policies_nodes, node.id)) && try(local.apic.new_interface_configuration, local.defaults.apic.new_interface_configuration) == false
])
}

module "aci_fex_interface_state" {
source = "./modules/terraform-aci-interface-state"

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

depends_on = [
module.aci_interface_state,
]
}
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_state: 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-state/.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 Type Module

Manages Interface Type

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-state/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- BEGIN_TF_DOCS -->
# Terraform ACI Interface Type Module

Manages Interface Type

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

## Examples

```hcl
module "aci_interface_type" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-type"
version = ">= 0.8.0"

pod_id = 2
node_id = 101
module = 2
port = 1
type = "downlink"
}
```

## 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: `1`. Maximum value: `4000`. | `number` | n/a | yes |
| <a name="input_module"></a> [module](#input\_module) | Interface Module. Minimum value: `1`. Maximum value: `9`. | `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_type"></a> [type](#input\_type) | Interface Type. Valid values are `uplink` or `downlink` | `string` | n/a | yes |

## Outputs

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

## Resources

| Name | Type |
|------|------|
| [aci_rest_managed.infraRsPortDirection](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 Type 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
26 changes: 26 additions & 0 deletions modules/terraform-aci-interface-state/examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- BEGIN_TF_DOCS -->
# Interface Type 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_type" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-state"
version = ">= 0.8.0"

pod_id = 1
node_id = 101
module = 1
port = 1
shutdown = false
}
```
<!-- END_TF_DOCS -->
10 changes: 10 additions & 0 deletions modules/terraform-aci-interface-state/examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module "aci_interface_type" {
source = "netascode/nac-aci/aci//modules/terraform-aci-interface-state"
version = ">= 0.8.0"

pod_id = 1
node_id = 101
module = 1
port = 1
shutdown = false
}
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-state/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aci_rest_managed" "fabricRsOosPath" {
dn = "uni/fabric/outofsvc/rsoosPath-[topology/pod-${var.pod_id}/paths-${var.node_id}/pathep-[eth${var.module}/${var.port}]]"
class_name = "fabricRsOosPath"
content = {
lc = var.shutdown ? "blacklist" : "in-service"
}
}
4 changes: 4 additions & 0 deletions modules/terraform-aci-interface-state/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."
}
50 changes: 50 additions & 0 deletions modules/terraform-aci-interface-state/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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: `1`. Maximum value: `4000`."
type = number

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

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

validation {
condition = try(var.module >= 1 && var.module <= 255, false)
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 "shutdown" {
description = "Shutdown interface."
type = bool
default = false
}



11 changes: 11 additions & 0 deletions modules/terraform-aci-interface-state/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"
}
}
}
Loading