Skip to content

Commit

Permalink
Add support for imported l4l7 device
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jan 30, 2024
1 parent 42d67fb commit 50b1303
Show file tree
Hide file tree
Showing 15 changed files with 258 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 @@ -301,6 +301,10 @@ repos:
args: ["./modules/terraform-aci-imported-contract"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-imported-contract/examples/complete"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-imported-l4l7-device"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-imported-l4l7-device/examples/complete"]
- id: terraform-docs-system
args: ["./modules/terraform-aci-inband-endpoint-group"]
- id: terraform-docs-system
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Make L3 PBR destination MAC optional
- Add `apic_include` option to `port_tracking` configuration
- Add support for Radius Provider
- Add support for imported L4L7 devices

## 0.8.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Additional example repositories:
| <a name="module_aci_health_score_evaluation_policy"></a> [aci\_health\_score\_evaluation\_policy](#module\_aci\_health\_score\_evaluation\_policy) | ./modules/terraform-aci-health-score-evaluation-policy | n/a |
| <a name="module_aci_igmp_interface_policy"></a> [aci\_igmp\_interface\_policy](#module\_aci\_igmp\_interface\_policy) | ./modules/terraform-aci-igmp-interface-policy | n/a |
| <a name="module_aci_igmp_snooping_policy"></a> [aci\_igmp\_snooping\_policy](#module\_aci\_igmp\_snooping\_policy) | ./modules/terraform-aci-igmp-snooping-policy | n/a |
| <a name="module_aci_imported_contract"></a> [aci\_imported\_contract](#module\_aci\_imported\_contract) | ./modules/terraform-aci-imported-contract | n/a |
| <a name="module_aci_imported_contract"></a> [aci\_imported\_contract](#module\_aci\_imported\_contract) | ./modules/terraform-aci-imported-l4l7-device | n/a |
| <a name="module_aci_inband_endpoint_group"></a> [aci\_inband\_endpoint\_group](#module\_aci\_inband\_endpoint\_group) | ./modules/terraform-aci-inband-endpoint-group | n/a |
| <a name="module_aci_inband_node_address"></a> [aci\_inband\_node\_address](#module\_aci\_inband\_node\_address) | ./modules/terraform-aci-inband-node-address | 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 |
Expand Down
29 changes: 29 additions & 0 deletions aci_tenants.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,35 @@ module "aci_l4l7_device" {
]
}

locals {
imported_l4l7_devices = flatten([
for tenant in local.tenants : [
for device in try(tenant.services.imported_l4l7_devices, []) : {
key = format("%s/%s", tenant.name, device.name)
tenant = tenant.name
source_tenant = device.tenant
source_device = "${device.name}${local.defaults.apic.tenants.services.l4l7_devices.name_suffix}"
description = try(device.description, "")
}
]
])
}

module "aci_imported_contract" {
source = "./modules/terraform-aci-imported-l4l7-device"

for_each = { for device in local.imported_l4l7_devices : device.key => device if local.modules.aci_imported_l4l7_device && var.manage_tenants }
tenant = each.value.tenant
source_tenant = each.value.source_tenant
source_device = each.value.source_device
description = each.value.description

depends_on = [
module.aci_tenant,
]
}


locals {
redirect_policies = flatten([
for tenant in local.tenants : [
Expand Down
1 change: 1 addition & 0 deletions defaults/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ modules:
aci_igmp_interface_policy: true
aci_igmp_snooping_policy: true
aci_imported_contract: true
aci_imported_l4l7_device: true
aci_inband_endpoint_group: true
aci_inband_node_address: true
aci_infra_dscp_translation_policy: true
Expand Down
34 changes: 34 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/.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 Imported L4L7 Device Module
ACI Imported L4L7 Device
Location in GUI:
`Tenants` » `XXX` » `Services` » `L4-L7` » `Imported Devices`
## Examples
```hcl
{{ include "./examples/complete/main.tf" }}
```
{{ .Requirements }}
{{ .Providers }}
{{ .Inputs }}
{{ .Outputs }}
{{ .Resources }}
output:
file: README.md
mode: replace

sort:
enabled: false
56 changes: 56 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!-- BEGIN_TF_DOCS -->
# Terraform ACI Imported L4L7 Device Module

ACI Imported L4L7 Device

Location in GUI:
`Tenants` » `XXX` » `Services` » `L4-L7` » `Imported Devices`

## Examples

```hcl
module "aci_imported_l4l7_device" {
source = "netascode/nac-aci/aci//modules/terraform-aci-imported-l4l7-device"
version = ">= 0.8.1"
tenant = "ABC"
source_tenant = "DEF"
source_device = "DEV1"
description = "My imported device"
}
```

## 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_source_tenant"></a> [source\_tenant](#input\_source\_tenant) | Source device tenant name. | `string` | n/a | yes |
| <a name="input_source_device"></a> [source\_device](#input\_source\_device) | L4L7 device name to be imported. | `string` | n/a | yes |
| <a name="input_description"></a> [description](#input\_description) | Imported device description. | `string` | `""` | no |

## Outputs

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

## Resources

| Name | Type |
|------|------|
| [aci_rest_managed.vnsLDevIf](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: |-
# Imported L4L7 Device 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 -->
# Imported L4L7 Device 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_imported_l4l7_device" {
source = "netascode/nac-aci/aci//modules/terraform-aci-imported-l4l7-device"
version = ">= 0.8.1"
tenant = "ABC"
source_tenant = "DEF"
source_device = "DEV1"
description = "My imported device"
}
```
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "aci_imported_l4l7_device" {
source = "netascode/nac-aci/aci//modules/terraform-aci-imported-l4l7-device"
version = ">= 0.8.1"

tenant = "ABC"
source_tenant = "DEF"
source_device = "DEV1"
description = "My imported device"
}
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"
}
}
}
8 changes: 8 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "aci_rest_managed" "vnsLDevIf" {
dn = "uni/tn-${var.tenant}/lDevIf-[uni/tn-${var.source_tenant}/lDevVip-${var.source_device}]"
class_name = "vnsLDevIf"
content = {
ldev = "uni/tn-${var.source_tenant}/lDevVip-${var.source_device}]"
description = var.description
}
}
4 changes: 4 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "dn" {
value = aci_rest_managed.vnsLDevIf.id
description = "Distinguished name of `vnsLDevIf` object."
}
40 changes: 40 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "tenant" {
description = "Tenant name."
type = string

validation {
condition = can(regex("^[a-zA-Z0-9_.-]{0,64}$", var.tenant))
error_message = "Allowed characters: `a`-`z`, `A`-`Z`, `0`-`9`, `_`, `.`, `-`. Maximum characters: 64."
}
}

variable "source_tenant" {
description = "Source device tenant name."
type = string

validation {
condition = can(regex("^[a-zA-Z0-9_.-]{0,64}$", var.source_tenant))
error_message = "Allowed characters: `a`-`z`, `A`-`Z`, `0`-`9`, `_`, `.`, `-`. Maximum characters: 64."
}
}

variable "source_device" {
description = "L4L7 device name to be imported."
type = string

validation {
condition = can(regex("^[a-zA-Z0-9_.-]{0,64}$", var.name))
error_message = "Allowed characters: `a`-`z`, `A`-`Z`, `0`-`9`, `_`, `.`, `-`. Maximum characters: 64."
}
}

variable "description" {
description = "Imported device description."
type = string
default = ""

validation {
condition = can(regex("^[a-zA-Z0-9\\!#$%()*,-./:;@ _{|}~?&+]{0,128}$", var.description))
error_message = "Allowed characters: `a`-`z`, `A`-`Z`, `0`-`9`, `\\`, `!`, `#`, `$`, `%`, `(`, `)`, `*`, `,`, `-`, `.`, `/`, `:`, `;`, `@`, ` `, `_`, `{`, `|`, }`, `~`, `?`, `&`, `+`. Maximum characters: 128."
}
}
11 changes: 11 additions & 0 deletions modules/terraform-aci-imported-l4l7-device/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"
}
}
}

0 comments on commit 50b1303

Please sign in to comment.