Skip to content

Commit d1bf2eb

Browse files
authored
usegEPG VM attributes support added. (#289)
1 parent 13adccb commit d1bf2eb

File tree

9 files changed

+100
-4
lines changed

9 files changed

+100
-4
lines changed

aci_tenants.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ locals {
565565
name = mac_statement.name
566566
mac = upper(mac_statement.mac)
567567
}]
568+
useg_attributes_vm_statements = [for vm_statement in try(useg_epg.useg_attributes.vm_statements, []) : {
569+
name = vm_statement.name
570+
type = try(vm_statement.type, local.defaults.apic.tenants.application_profiles.useg_endpoint_groups.useg_attributes.vm_statements.type)
571+
operator = try(vm_statement.operator, local.defaults.apic.tenants.application_profiles.useg_endpoint_groups.useg_attributes.vm_statements.operator)
572+
value = vm_statement.value
573+
category = try(vm_statement.category, null)
574+
label = try(vm_statement.label, null)
575+
}]
568576
subnets = [for subnet in try(useg_epg.subnets, []) : {
569577
description = try(subnet.description, "")
570578
ip = subnet.ip
@@ -639,6 +647,7 @@ module "aci_useg_endpoint_group" {
639647
match_type = each.value.useg_attributes_match_type
640648
ip_statements = each.value.useg_attributes_ip_statements
641649
mac_statements = each.value.useg_attributes_mac_statements
650+
vm_statements = each.value.useg_attributes_vm_statements
642651
subnets = each.value.subnets
643652
vmware_vmm_domains = each.value.vmware_vmm_domains
644653
static_leafs = [for sl in try(each.value.static_leafs, []) : {

defaults/defaults.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ defaults:
11811181
match_type: any
11821182
ip_statements:
11831183
use_epg_subnet: true
1184+
vm_statements:
1185+
type: vm-name
1186+
operator: equals
11841187
subnets:
11851188
primary_ip: false
11861189
public: false

modules/terraform-aci-useg-endpoint-group/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ module "aci_useg_endpoint_group" {
5555
name = "mac_2"
5656
mac = "02:aa:68:22:58:d2"
5757
}]
58+
59+
vm_statements = [{
60+
name = "vm_name"
61+
value = "BackEnd"
62+
}, {
63+
name = "operating_system"
64+
value = "Win11"
65+
type = "guest-os"
66+
}]
67+
5868
subnets = [{
5969
description = "Subnet Description"
6070
ip = "1.2.2.1/24"
@@ -86,13 +96,13 @@ module "aci_useg_endpoint_group" {
8696
| Name | Version |
8797
|------|---------|
8898
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
89-
| <a name="requirement_aci"></a> [aci](#requirement\_aci) | >= 2.0.0 |
99+
| <a name="requirement_aci"></a> [aci](#requirement\_aci) | >= 2.15.0 |
90100

91101
## Providers
92102

93103
| Name | Version |
94104
|------|---------|
95-
| <a name="provider_aci"></a> [aci](#provider\_aci) | >= 2.0.0 |
105+
| <a name="provider_aci"></a> [aci](#provider\_aci) | >= 2.15.0 |
96106

97107
## Inputs
98108

@@ -123,6 +133,7 @@ module "aci_useg_endpoint_group" {
123133
| <a name="input_match_type"></a> [match\_type](#input\_match\_type) | Match type for IP type uSeg Attributes | `string` | `"any"` | no |
124134
| <a name="input_ip_statements"></a> [ip\_statements](#input\_ip\_statements) | IP Statements for IP type uSeg Attributes | <pre>list(object({<br/> name = string<br/> use_epg_subnet = bool<br/> ip = optional(string, "")<br/> }))</pre> | `[]` | no |
125135
| <a name="input_mac_statements"></a> [mac\_statements](#input\_mac\_statements) | MAC Statements for MAC type uSeg Attributes | <pre>list(object({<br/> name = string<br/> mac = string<br/> }))</pre> | `[]` | no |
136+
| <a name="input_vm_statements"></a> [vm\_statements](#input\_vm\_statements) | VM Statements for VM type uSeg Attributes | <pre>list(object({<br/> name = string<br/> type = optional(string, "vm-name")<br/> operator = optional(string, "equals")<br/> value = string<br/> category = optional(string, "")<br/> label = optional(string, "")<br/> }))</pre> | `[]` | no |
126137
| <a name="input_l4l7_address_pools"></a> [l4l7\_address\_pools](#input\_l4l7\_address\_pools) | List of EPG L4/L7 Address Pools. | <pre>list(object({<br/> name = string<br/> gateway_address = string<br/> from = optional(string, "")<br/> to = optional(string, "")<br/> }))</pre> | `[]` | no |
127138

128139
## Outputs
@@ -160,6 +171,7 @@ module "aci_useg_endpoint_group" {
160171
| [aci_rest_managed.fvRsVmmVSwitchEnhancedLagPol](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
161172
| [aci_rest_managed.fvSubnet](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
162173
| [aci_rest_managed.fvUplinkOrderCont](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
174+
| [aci_rest_managed.fvVmAttr](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
163175
| [aci_rest_managed.fvnsUcastAddrBlk](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
164176
| [aci_rest_managed.ipNexthopEpP](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |
165177
| [aci_rest_managed.tagInst](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/rest_managed) | resource |

modules/terraform-aci-useg-endpoint-group/examples/complete/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ module "aci_useg_endpoint_group" {
5858
name = "mac_2"
5959
mac = "02:aa:68:22:58:d2"
6060
}]
61+
62+
vm_statements = [{
63+
name = "vm_name"
64+
value = "BackEnd"
65+
}, {
66+
name = "operating_system"
67+
value = "Win11"
68+
type = "guest-os"
69+
}]
70+
6171
subnets = [{
6272
description = "Subnet Description"
6373
ip = "1.2.2.1/24"

modules/terraform-aci-useg-endpoint-group/examples/complete/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ module "aci_useg_endpoint_group" {
4444
name = "mac_2"
4545
mac = "02:aa:68:22:58:d2"
4646
}]
47+
48+
vm_statements = [{
49+
name = "vm_name"
50+
value = "BackEnd"
51+
}, {
52+
name = "operating_system"
53+
value = "Win11"
54+
type = "guest-os"
55+
}]
56+
4757
subnets = [{
4858
description = "Subnet Description"
4959
ip = "1.2.2.1/24"

modules/terraform-aci-useg-endpoint-group/examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
required_providers {
66
aci = {
77
source = "CiscoDevNet/aci"
8-
version = ">= 2.0.0"
8+
version = ">= 2.15.0"
99
}
1010
}
1111
}

modules/terraform-aci-useg-endpoint-group/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ resource "aci_rest_managed" "fvMacAttr" {
8787
]
8888
}
8989

90+
resource "aci_rest_managed" "fvVmAttr" {
91+
for_each = { for vm_statement in var.vm_statements : vm_statement.name => vm_statement }
92+
dn = "${aci_rest_managed.fvAEPg.dn}/crtrn/vmattr-${each.value.name}"
93+
class_name = "fvVmAttr"
94+
content = {
95+
operator = each.value.operator
96+
type = each.value.type
97+
value = each.value.value
98+
category = each.value.category
99+
labelName = each.value.label
100+
name = each.value.name
101+
}
102+
103+
depends_on = [
104+
aci_rest_managed.fvCrtrn
105+
]
106+
}
107+
90108
resource "aci_rest_managed" "fvSubnet" {
91109
for_each = { for subnet in var.subnets : subnet.ip => subnet }
92110
dn = "${aci_rest_managed.fvAEPg.dn}/subnet-[${each.value.ip}]"

modules/terraform-aci-useg-endpoint-group/variables.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,40 @@ variable "mac_statements" {
378378
}
379379
}
380380

381+
variable "vm_statements" {
382+
description = "VM Statements for VM type uSeg Attributes"
383+
type = list(object({
384+
name = string
385+
type = optional(string, "vm-name")
386+
operator = optional(string, "equals")
387+
value = string
388+
category = optional(string, "")
389+
label = optional(string, "")
390+
}))
391+
default = []
392+
393+
validation {
394+
condition = alltrue([
395+
for vm_statement in var.vm_statements : can(regex("^[a-zA-Z0-9_.:-]{0,64}$", vm_statement.name))
396+
])
397+
error_message = "`name`: Allowed characters: `a`-`z`, `A`-`Z`, `0`-`9`, `_`, `.`, `:`, `-`. Maximum characters: 64."
398+
}
399+
400+
validation {
401+
condition = alltrue([
402+
for vm_statement in var.vm_statements : try(contains(["vm-name", "guest-os", "hv", "vm", "vnic", "domain", "rootContName", "custom-label", "tag", "vm-folder", "vmfolder-path"], vm_statement.type), false) || try(tonumber(vm_statement.type) >= 0 && tonumber(vm_statement.type) <= 10, false)
403+
])
404+
error_message = "`type`: Allowed values are `vm-name`, `guest-os`, `hv`, `vm`, `vnic`, `domain`, `rootContName`, `custom-label`, `tag`, `vm-folder`, `vmfolder-path` or a number between 0 and 10."
405+
}
406+
407+
validation {
408+
condition = alltrue([
409+
for vm_statement in var.vm_statements : try(contains(["equals", "contains", "startsWith", "endsWith", "notEquals"], vm_statement.operator), false) || try(tonumber(vm_statement.operator) >= 0 && tonumber(vm_statement.operator) <= 4, false)
410+
])
411+
error_message = "`operator`: Allowed values are `equals`, `contains`, `startsWith`, `endsWith`, `notEquals` or a number between 0 and 4."
412+
}
413+
}
414+
381415
variable "l4l7_address_pools" {
382416
description = "List of EPG L4/L7 Address Pools."
383417
type = list(object({

modules/terraform-aci-useg-endpoint-group/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
required_providers {
66
aci = {
77
source = "CiscoDevNet/aci"
8-
version = ">= 2.0.0"
8+
version = ">= 2.15.0"
99
}
1010
}
1111
}

0 commit comments

Comments
 (0)