Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to reference module nsgs in the nsg rules #962

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/network/vars-network.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ allow_rules_public_lb = {
# "Allow TCP ingress to public load balancers for SSL traffic from anywhere" : {
# protocol = 6, port = 443, source = "0.0.0.0/0", source_type = "CIDR_BLOCK",
# },
# "Allow UDP egress to workers port range 50000-52767 from Public LBs" : {
# protocol = 17, destination_port_min = 50000, destination_port_max=52767, destination = "workers", destination_type = "NETWORK_SECURITY_GROUP"
# },
}

allow_rules_workers = {
# "Allow TCP ingress to workers for port 8080 from VCN" : {
# protocol = 6, port = 8080, source = "10.0.0.0/16", source_type = "CIDR_BLOCK",
# },
# "Allow UDP ingress to workers for port range 50000-52767 from Public LBs" : {
# protocol = 17, destination_port_min = 50000, destination_port_max=52767, source = "pub_lb", source_type = "NETWORK_SECURITY_GROUP"
# },
# "Allow TCP ingress to workers for port range 8888-8888 from existing NSG" : {
# protocol = 6, destination_port_min = 8888, destination_port_max=8888, source = "ocid1.networksecuritygroup.oc1.eu-frankfurt-1.aaaaaaaai6z4le2ji7dkpmuwff4525b734wrjlifjqkrzlr5qctgxdsyoyra", source_type = "NETWORK_SECURITY_GROUP"
# },
}

# Dynamic routing gateway (DRG)
Expand Down
16 changes: 14 additions & 2 deletions modules/network/rules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ locals {
network_security_group_id = lookup(y, "nsg_id")
direction = contains(keys(y), "source") ? "INGRESS" : "EGRESS"
protocol = lookup(y, "protocol")
source = lookup(y, "source", null)
source = (
alltrue([
upper(lookup(y, "source_type", "")) == local.rule_type_nsg,
length(regexall("ocid\\d+\\.networksecuritygroup", lower(lookup(y, "source", "")))) == 0]) ?
lookup(local.all_nsg_ids, lower(lookup(y, "source", "")), null) :
lookup(y, "source", null)
)
source_type = lookup(y, "source_type", null)
destination = lookup(y, "destination", null)
destination = (
alltrue([
upper(lookup(y, "destination_type", "")) == local.rule_type_nsg,
length(regexall("ocid\\d+\\.networksecuritygroup", lower(lookup(y, "destination", "")))) == 0]) ?
lookup(local.all_nsg_ids, lower(lookup(y, "destination", "")), null) :
lookup(y, "destination", null)
)
destination_type = lookup(y, "destination_type", null)
}) }

Expand Down