Skip to content

Commit

Permalink
Add track lists and track members (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
juchowan authored May 23, 2024
1 parent 3753b30 commit cc5cf52
Show file tree
Hide file tree
Showing 28 changed files with 678 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ repos:
args: ["./modules/terraform-aci-tenant-span-source-group"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-tenant-span-source-group/examples/complete"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-track-list"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-track-member"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-trust-control-policy"]
- id: terraform-docs-system
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Additional example repositories:
| <a name="module_aci_tenant"></a> [aci\_tenant](#module\_aci\_tenant) | ./modules/terraform-aci-tenant | n/a |
| <a name="module_aci_tenant_span_destination_group"></a> [aci\_tenant\_span\_destination\_group](#module\_aci\_tenant\_span\_destination\_group) | ./modules/terraform-aci-tenant-span-destination-group | n/a |
| <a name="module_aci_tenant_span_source_group"></a> [aci\_tenant\_span\_source\_group](#module\_aci\_tenant\_span\_source\_group) | ./modules/terraform-aci-tenant-span-source-group | n/a |
| <a name="module_aci_track_list"></a> [aci\_track\_list](#module\_aci\_track\_list) | ./modules/terraform-aci-track-list | n/a |
| <a name="module_aci_track_member"></a> [aci\_track\_member](#module\_aci\_track\_member) | ./modules/terraform-aci-track-member | n/a |
| <a name="module_aci_trust_control_policy"></a> [aci\_trust\_control\_policy](#module\_aci\_trust\_control\_policy) | ./modules/terraform-aci-trust-control-policy | n/a |
| <a name="module_aci_user"></a> [aci\_user](#module\_aci\_user) | ./modules/terraform-aci-user | n/a |
| <a name="module_aci_vlan_pool"></a> [aci\_vlan\_pool](#module\_aci\_vlan\_pool) | ./modules/terraform-aci-vlan-pool | n/a |
Expand Down
66 changes: 66 additions & 0 deletions aci_tenants.tf
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ locals {
prefix = sr.prefix
preference = try(sr.preference, local.defaults.apic.tenants.l3outs.node_profiles.nodes.static_routes.preference)
bfd = try(sr.bfd, local.defaults.apic.tenants.l3outs.node_profiles.nodes.static_routes.bfd)
track_list = try(sr.track_list, null)
next_hops = [for nh in try(sr.next_hops, []) : {
ip = nh.ip
preference = try(nh.preference, local.defaults.apic.tenants.l3outs.node_profiles.nodes.static_routes.next_hops.preference)
Expand Down Expand Up @@ -889,6 +890,7 @@ locals {
prefix = sr.prefix
preference = try(sr.preference, local.defaults.apic.tenants.l3outs.nodes.static_routes.preference)
bfd = try(sr.bfd, local.defaults.apic.tenants.l3outs.node_profiles.nodes.static_routes.bfd)
track_list = try(sr.track_list, null)
next_hops = [for nh in try(sr.next_hops, []) : {
ip = nh.ip
preference = try(nh.preference, local.defaults.apic.tenants.l3outs.nodes.static_routes.next_hops.preference)
Expand Down Expand Up @@ -3249,3 +3251,67 @@ module "aci_tenant_span_source_group" {
module.aci_tenant,
]
}

locals {
track_lists = flatten([
for tenant in local.tenants : [
for policy in try(tenant.policies.track_lists, []) : {
key = format("%s/%s", tenant.name, policy.name)
tenant = tenant.name
name = "${policy.name}${local.defaults.apic.tenants.policies.track_lists.name_suffix}"
description = try(policy.description, "")
type = try(policy.type, local.defaults.apic.tenants.policies.track_lists.type)
percentage_up = try(policy.percentage_up, local.defaults.apic.tenants.policies.track_lists.percentage_up)
percentage_down = try(policy.percentage_down, local.defaults.apic.tenants.policies.track_lists.percentage_down)
weight_up = try(policy.weight_up, local.defaults.apic.tenants.policies.track_lists.weight_up)
weight_down = try(policy.weight_down, local.defaults.apic.tenants.policies.track_lists.weight_down)
track_members = try(policy.track_members, [])
}
]
])
}

module "aci_track_list" {
source = "./modules/terraform-aci-track-list"

for_each = { for track_list in local.track_lists : track_list.key => track_list if local.modules.aci_track_list && var.manage_tenants }
tenant = each.value.tenant
name = each.value.name
description = each.value.description
type = each.value.type
percentage_up = each.value.percentage_up
percentage_down = each.value.percentage_down
weight_up = each.value.weight_up
weight_down = each.value.weight_down
track_members = each.value.track_members
}

locals {
track_members = flatten([
for tenant in local.tenants : [
for policy in try(tenant.policies.track_members, []) : {
key = format("%s/%s", tenant.name, policy.name)
tenant = tenant.name
name = policy.name
description = try(policy.description, "")
destination_ip = policy.destination_ip
scope_type = policy.scope_type
scope = policy.scope
ip_sla_policy = policy.ip_sla_policy
}
]
])
}

module "aci_track_member" {
source = "./modules/terraform-aci-track-member"

for_each = { for member in local.track_members : member.key => member if local.modules.aci_track_member && var.manage_tenants }
tenant = each.value.tenant
name = each.value.name
description = each.value.description
destination_ip = each.value.destination_ip
scope_type = each.value.scope_type
scope = each.value.scope
ip_sla_policy = each.value.ip_sla_policy
}
7 changes: 7 additions & 0 deletions defaults/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,13 @@ defaults:
auto_configuration: true
on_link: true
router_address: false
track_lists:
name_suffix: ""
type: percentage
percentage_up: 0
percentage_down: 1
weight_up: 0
weight_down: 1
services:
l4l7_devices:
name_suffix: ""
Expand Down
2 changes: 2 additions & 0 deletions defaults/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ modules:
aci_tenant: true
aci_tenant_span_destination_group: true
aci_tenant_span_source_group: true
aci_track_list: true
aci_track_member: true
aci_trust_control_policy: true
aci_user: true
aci_vlan_pool: true
Expand Down
3 changes: 2 additions & 1 deletion modules/terraform-aci-l3out-node-profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module "aci_l3out_node_profile" {
| <a name="input_tenant"></a> [tenant](#input\_tenant) | Tenant name. | `string` | n/a | yes |
| <a name="input_l3out"></a> [l3out](#input\_l3out) | L3out name. | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Node profile name. | `string` | n/a | yes |
| <a name="input_nodes"></a> [nodes](#input\_nodes) | List of nodes. Allowed values `node_id`: 1-4000. Allowed values `pod_id`: 1-255. Default value `pod_id`: 1. Default value `router_id_as_loopback`: true. Allowed values `static_routes.preference`: 1-255. Default value `static_routes.preference`: 1. Default value `static_routes.bfd`: false. Allowed values `static_routes.next_hops.preference`: 0-255. Default value `static_routes.next_hops.preference`: 1. Choices `type`: `prefix`, `none`. Default value `type`: `prefix`. | <pre>list(object({<br> node_id = number<br> pod_id = optional(number, 1)<br> router_id = string<br> router_id_as_loopback = optional(bool, true)<br> loopback = optional(string)<br> mpls_transport_loopback = optional(string)<br> segment_id = optional(number)<br> static_routes = optional(list(object({<br> prefix = string<br> description = optional(string, "")<br> preference = optional(number, 1)<br> bfd = optional(bool, false)<br> next_hops = optional(list(object({<br> ip = string<br> preference = optional(number, 1)<br> type = optional(string, "prefix")<br> })), [])<br> })), [])<br> }))</pre> | `[]` | no |
| <a name="input_nodes"></a> [nodes](#input\_nodes) | List of nodes. Allowed values `node_id`: 1-4000. Allowed values `pod_id`: 1-255. Default value `pod_id`: 1. Default value `router_id_as_loopback`: true. Allowed values `static_routes.preference`: 1-255. Default value `static_routes.preference`: 1. Default value `static_routes.bfd`: false. Allowed values `static_routes.next_hops.preference`: 0-255. Default value `static_routes.next_hops.preference`: 1. Choices `type`: `prefix`, `none`. Default value `type`: `prefix`. | <pre>list(object({<br> node_id = number<br> pod_id = optional(number, 1)<br> router_id = string<br> router_id_as_loopback = optional(bool, true)<br> loopback = optional(string)<br> mpls_transport_loopback = optional(string)<br> segment_id = optional(number)<br> static_routes = optional(list(object({<br> prefix = string<br> description = optional(string, "")<br> preference = optional(number, 1)<br> bfd = optional(bool, false)<br> track_list = optional(string)<br> next_hops = optional(list(object({<br> ip = string<br> preference = optional(number, 1)<br> type = optional(string, "prefix")<br> })), [])<br> })), [])<br> }))</pre> | `[]` | no |
| <a name="input_bgp_peers"></a> [bgp\_peers](#input\_bgp\_peers) | List of BGP peers. Allowed values `remote_as`: 0-4294967295. Default value `allow_self_as`: false. Default value `as_override`: false. Default value `disable_peer_as_check`: false. Default value `next_hop_self`: false. Default value `send_community`: false. Default value `send_ext_community`: false. Allowed values `allowed_self_as_count`: 1-10. Default value `allowed_self_as_count`: 3. Default value `bfd`: false. Default value `disable_connected_check`: false. Allowed values `ttl`: 1-255. Default value `ttl`: 1. Allowed values `weight`: 0-65535. Default value `weight`: 0. Default value `remove_all_private_as`: false. Default value `remove_private_as`: false. Default value `replace_private_as_with_local_as`: false. Default value `unicast_address_family`: true. Default value `multicast_address_family`: true. Default value `admin_state`: true. Allowed values `local_as`: 0-4294967295. Choices `as_propagate`: `none`, `no-prepend`, `replace-as`, `dual-as`. Default value `as_propagate`: `none`. | <pre>list(object({<br> ip = string<br> remote_as = string<br> description = optional(string, "")<br> allow_self_as = optional(bool, false)<br> as_override = optional(bool, false)<br> disable_peer_as_check = optional(bool, false)<br> next_hop_self = optional(bool, false)<br> send_community = optional(bool, false)<br> send_ext_community = optional(bool, false)<br> password = optional(string)<br> allowed_self_as_count = optional(number, 3)<br> bfd = optional(bool, false)<br> disable_connected_check = optional(bool, false)<br> ttl = optional(number, 1)<br> weight = optional(number, 0)<br> remove_all_private_as = optional(bool, false)<br> remove_private_as = optional(bool, false)<br> replace_private_as_with_local_as = optional(bool, false)<br> unicast_address_family = optional(bool, true)<br> multicast_address_family = optional(bool, true)<br> admin_state = optional(bool, true)<br> local_as = optional(number)<br> as_propagate = optional(string, "none")<br> peer_prefix_policy = optional(string)<br> export_route_control = optional(string)<br> import_route_control = optional(string)<br> }))</pre> | `[]` | no |
| <a name="input_multipod"></a> [multipod](#input\_multipod) | Multipod L3out flag. | `bool` | `false` | no |
| <a name="input_remote_leaf"></a> [remote\_leaf](#input\_remote\_leaf) | Remote leaf L3out flag. | `bool` | `false` | no |
Expand Down Expand Up @@ -121,6 +121,7 @@ module "aci_l3out_node_profile" {
| [aci_rest_managed.bgpRsPeerToProfile_import](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.ipNexthopP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.ipRouteP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.ipRsRouteTrack](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.l3extInfraNodeP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.l3extLNodeP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.l3extLoopBackIfP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
Expand Down
10 changes: 10 additions & 0 deletions modules/terraform-aci-l3out-node-profile/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ locals {
description = sr.description
preference = sr.preference
bfd = sr.bfd
track_list = sr.track_list
}
}
]
Expand Down Expand Up @@ -69,6 +70,15 @@ resource "aci_rest_managed" "ipRouteP" {
}
}

resource "aci_rest_managed" "ipRsRouteTrack" {
for_each = { for item in local.static_routes : item.key => item.value if item.value.track_list != null }
dn = "${aci_rest_managed.ipRouteP[each.key].dn}/rsRouteTrack"
class_name = "ipRsRouteTrack"
content = {
tDn = "uni/tn-${var.tenant}/tracklist-${each.value.track_list}"
}
}

resource "aci_rest_managed" "ipNexthopP" {
for_each = { for item in local.next_hops : item.key => item.value }
dn = "${aci_rest_managed.ipRouteP[each.value.static_route].dn}/nh-[${each.value.ip}]"
Expand Down
1 change: 1 addition & 0 deletions modules/terraform-aci-l3out-node-profile/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ variable "nodes" {
description = optional(string, "")
preference = optional(number, 1)
bfd = optional(bool, false)
track_list = optional(string)
next_hops = optional(list(object({
ip = string
preference = optional(number, 1)
Expand Down
34 changes: 34 additions & 0 deletions modules/terraform-aci-track-list/.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 Track List Module
Manages ACI Track List
Location in GUI:
`Tenants` » `XXX` » `Policies` » `Protocol` » `IP SLA` » `Track Lists`
## Examples
```hcl
{{ include "./examples/complete/main.tf" }}
```
{{ .Requirements }}
{{ .Providers }}
{{ .Inputs }}
{{ .Outputs }}
{{ .Resources }}
output:
file: README.md
mode: replace

sort:
enabled: false
66 changes: 66 additions & 0 deletions modules/terraform-aci-track-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!-- BEGIN_TF_DOCS -->
# Terraform ACI Track List Module

Manages ACI Track List

Location in GUI:
`Tenants` » `XXX` » `Policies` » `Protocol` » `IP SLA` » `Track Lists`

## Examples

```hcl
module "aci_track_list" {
source = "netascode/nac-aci/aci//modules/terraform-aci-track-list"
version = ">= 0.8.0"
tenant = "ABC"
name = "TRACK1"
description = "My Description"
percentage_down = 10
percentage_up = 20
type = "percentage"
track_members = ["mem1", "mem2"]
}
```

## 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_tenant"></a> [tenant](#input\_tenant) | Tenant name. | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Track List name. | `string` | n/a | yes |
| <a name="input_description"></a> [description](#input\_description) | Description. | `string` | `""` | no |
| <a name="input_type"></a> [type](#input\_type) | Type of Track List. Allowed values: `percentage`, `weight`. | `string` | `"percentage"` | no |
| <a name="input_percentage_down"></a> [percentage\_down](#input\_percentage\_down) | Down Threshold percentage. Minimum value: 0. Maximum value: 100. | `number` | `0` | no |
| <a name="input_percentage_up"></a> [percentage\_up](#input\_percentage\_up) | Up Threshold percentage. Minimum value: 0. Maximum value: 100. | `number` | `0` | no |
| <a name="input_weight_down"></a> [weight\_down](#input\_weight\_down) | Down Threshold weight. Minimum value: 0. Maximum value: 255. | `number` | `0` | no |
| <a name="input_weight_up"></a> [weight\_up](#input\_weight\_up) | Up Threshold weight. Minimum value: 0. Maximum value: 255. | `number` | `0` | no |
| <a name="input_track_members"></a> [track\_members](#input\_track\_members) | Track List members. | `list(string)` | `[]` | no |

## Outputs

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

## Resources

| Name | Type |
|------|------|
| [aci_rest_managed.fvRsOtmListMember](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
| [aci_rest_managed.fvTrackList](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: |-
# Track List 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
29 changes: 29 additions & 0 deletions modules/terraform-aci-track-list/examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- BEGIN_TF_DOCS -->
# ND RA Prefix Policy 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_nd_ra_prefix_policy" {
source = "netascode/nac-aci/aci//modules/terraform-aci-nd-ra-prefix-policy"
version = ">= 0.8.0"
tenant = "ABC"
name = "NDRA1"
description = "My Description"
valid_lifetime = 1000
preferred_lifetime = 10000
auto_configuration = false
on_link = false
router_address = false
}
```
<!-- END_TF_DOCS -->
12 changes: 12 additions & 0 deletions modules/terraform-aci-track-list/examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "aci_track_list" {
source = "netascode/nac-aci/aci//modules/terraform-aci-track-list"
version = ">= 0.8.0"

tenant = "ABC"
name = "TRACK1"
description = "My Description"
percentage_down = 10
percentage_up = 20
type = "percentage"
track_members = ["mem1", "mem2"]
}
11 changes: 11 additions & 0 deletions modules/terraform-aci-track-list/examples/complete/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

0 comments on commit cc5cf52

Please sign in to comment.