Skip to content

Commit b0f8bad

Browse files
committed
- vcd_nsxt_firewall Module Release Version 1.3.0
- Added a Locals Block to create a global lookup table (map) that will contain all the different entities' ids with their names as keys. This will simplify and generalize the id resolution in the firewall rule creation. - Updated the "source_ids", "destination_ids", and "app_port_profile_ids" in the firewall rule creation to use the new map - Updated the Source URL in the Example Usage Section to the latest (v1.3.0) version of the vcd_nsxt_distributed_firewall Module - Updated the app_port_profiles Variable Required Value to "yes" in the Inputs Section of the README
1 parent 86d4a53 commit b0f8bad

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This Terraform module deploys NSX-T Edge Gateway Firewall Rules into an existing
2525
| vdc_org_name | The name of the Data Center Group Organization in VCD | string | `"Organization Name Format: <Account_Number>-<Region>-<Account_Name>"` | yes |
2626
| vdc_group_name | The name of the Data Center Group in VCD | string | `"Data Center Group Name Format: <Account_Number>-<Region>-<Account_Name> <datacenter group>"` | yes |
2727
| vdc_edge_name | Name of the Data Center Group Edge Gateway | string | `"Edge Gateway Name Format: <Account_Number>-<Region>-<Edge_GW_Identifier>-<edge>"` | yes |
28-
| app_port_profiles | Map of app port profiles with their corresponding scopes | map(string) | {} | no |
28+
| app_port_profiles | Map of app port profiles with their corresponding scopes | map(string) | {} | yes |
2929
| ip_set_names | List of IP set names | list(string) | [] | yes |
3030
| dynamic_security_group_names | List of dynamic security group names | list(string) | [] | no |
3131
| security_group_names | List of security group names | list(string) | [] | no |
@@ -42,7 +42,7 @@ This Terraform module deploys NSX-T Edge Gateway Firewall Rules into an existing
4242

4343
```terraform
4444
module "vcd_nsxt_firewall" {
45-
source = "github.com/global-vmware/vcd_nsxt_firewall.git?ref=v1.1.0"
45+
source = "github.com/global-vmware/vcd_nsxt_firewall.git?ref=v1.3.0"
4646
4747
vdc_org_name = "<VDC-ORG-NAME>"
4848
vdc_group_name = "<VDC-GRP-NAME>"

main.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ data "vcd_nsxt_security_group" "security_groups" {
5050
name = each.value
5151
}
5252

53+
locals {
54+
id_lookup = merge(
55+
{ for name, profile in data.vcd_nsxt_app_port_profile.app_port_profiles : name => profile.id },
56+
{ for name, group in data.vcd_nsxt_security_group.security_groups : name => group.id },
57+
{ for name, group in data.vcd_nsxt_dynamic_security_group.dynamic_security_groups : name => group.id },
58+
{ for name, set in data.vcd_nsxt_ip_set.ip_sets : name => set.id }
59+
)
60+
}
61+
5362
resource "vcd_nsxt_firewall" "edge_firewall" {
5463
edge_gateway_id = data.vcd_nsxt_edgegateway.edge_gateway.id
5564

@@ -62,9 +71,9 @@ resource "vcd_nsxt_firewall" "edge_firewall" {
6271
action = rule.value["action"]
6372
enabled = lookup(rule.value, "enabled", true)
6473
logging = lookup(rule.value, "logging", false)
65-
source_ids = try(length(rule.value["source_ids"]), 0) > 0 ? [for id in rule.value["source_ids"]: try(data.vcd_nsxt_security_group.security_groups[id].id, try(data.vcd_nsxt_dynamic_security_group.dynamic_security_groups[id].id, data.vcd_nsxt_ip_set.ip_sets[id].id)) if id != null && id != ""] : null
66-
destination_ids = try(length(rule.value["destination_ids"]), 0) > 0 ? [for id in rule.value["destination_ids"]: try(data.vcd_nsxt_security_group.security_groups[id].id, try(data.vcd_nsxt_dynamic_security_group.dynamic_security_groups[id].id, data.vcd_nsxt_ip_set.ip_sets[id].id)) if id != null && id != ""] : null
67-
app_port_profile_ids = try(length(rule.value["app_port_profile_ids"]), 0) > 0 ? [for name in rule.value["app_port_profile_ids"]: data.vcd_nsxt_app_port_profile.app_port_profiles[name].id if name != null && name != ""] : null
74+
source_ids = try(length(rule.value["source_ids"]), 0) > 0 ? [for name in rule.value["source_ids"]: local.id_lookup[name] if contains(keys(local.id_lookup), name) && name != null && name != ""] : null
75+
destination_ids = try(length(rule.value["destination_ids"]), 0) > 0 ? [for name in rule.value["destination_ids"]: local.id_lookup[name] if contains(keys(local.id_lookup), name) && name != null && name != ""] : null
76+
app_port_profile_ids = try(length(rule.value["app_port_profile_ids"]), 0) > 0 ? [for name in rule.value["app_port_profile_ids"]: local.id_lookup[name] if contains(keys(local.id_lookup), name) && name != null && name != ""] : null
6877
}
6978
}
7079
}

0 commit comments

Comments
 (0)