Skip to content

Commit ce2de7a

Browse files
robo-caphyder
authored andcommitted
feat: add support to reference module nsgs in the nsg rules
1 parent dc41e91 commit ce2de7a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

examples/network/vars-network.auto.tfvars

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,21 @@ allow_rules_public_lb = {
5151
# "Allow TCP ingress to public load balancers for SSL traffic from anywhere" : {
5252
# protocol = 6, port = 443, source = "0.0.0.0/0", source_type = "CIDR_BLOCK",
5353
# },
54+
# "Allow UDP egress to workers port range 50000-52767 from Public LBs" : {
55+
# protocol = 17, destination_port_min = 50000, destination_port_max=52767, destination = "workers", destination_type = "NETWORK_SECURITY_GROUP"
56+
# },
5457
}
5558

5659
allow_rules_workers = {
5760
# "Allow TCP ingress to workers for port 8080 from VCN" : {
5861
# protocol = 6, port = 8080, source = "10.0.0.0/16", source_type = "CIDR_BLOCK",
5962
# },
63+
# "Allow UDP ingress to workers for port range 50000-52767 from Public LBs" : {
64+
# protocol = 17, destination_port_min = 50000, destination_port_max=52767, source = "pub_lb", source_type = "NETWORK_SECURITY_GROUP"
65+
# },
66+
# "Allow TCP ingress to workers for port range 8888-8888 from existing NSG" : {
67+
# protocol = 6, destination_port_min = 8888, destination_port_max=8888, source = "ocid1.networksecuritygroup.oc1.eu-frankfurt-1.aaaaaaaai6z4le2ji7dkpmuwff4525b734wrjlifjqkrzlr5qctgxdsyoyra", source_type = "NETWORK_SECURITY_GROUP"
68+
# },
6069
}
6170

6271
# Dynamic routing gateway (DRG)

modules/network/rules.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ locals {
2424
network_security_group_id = lookup(y, "nsg_id")
2525
direction = contains(keys(y), "source") ? "INGRESS" : "EGRESS"
2626
protocol = lookup(y, "protocol")
27-
source = lookup(y, "source", null)
27+
source = (
28+
alltrue([
29+
upper(lookup(y, "source_type", "")) == local.rule_type_nsg,
30+
length(regexall("ocid\\d+\\.networksecuritygroup", lower(lookup(y, "source", "")))) == 0]) ?
31+
lookup(local.all_nsg_ids, lower(lookup(y, "source", "")), null) :
32+
lookup(y, "source", null)
33+
)
2834
source_type = lookup(y, "source_type", null)
29-
destination = lookup(y, "destination", null)
35+
destination = (
36+
alltrue([
37+
upper(lookup(y, "destination_type", "")) == local.rule_type_nsg,
38+
length(regexall("ocid\\d+\\.networksecuritygroup", lower(lookup(y, "destination", "")))) == 0]) ?
39+
lookup(local.all_nsg_ids, lower(lookup(y, "destination", "")), null) :
40+
lookup(y, "destination", null)
41+
)
3042
destination_type = lookup(y, "destination_type", null)
3143
}) }
3244

0 commit comments

Comments
 (0)