Skip to content

Commit a8ed3e9

Browse files
authored
Merge pull request #12 from dnks0/feature/dbx-proxy
added support for existing Security groups of an NLB in proxy-only mode
2 parents 2784f60 + 593c7ed commit a8ed3e9

4 files changed

Lines changed: 35 additions & 0 deletions

File tree

terraform/aws/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module "load_balancer" {
3636

3737
vpc_id = local.vpc_id
3838
subnet_ids = local.subnet_ids
39+
subnet_cidrs = local.subnet_cidrs
3940

4041
dbx_proxy_health_port = var.dbx_proxy_health_port
4142
dbx_proxy_listener = var.dbx_proxy_listener

terraform/aws/modules/load-balancer/local.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ locals {
44
nlb_dns_name = var.bootstrap_load_balancer ? aws_lb.this[0].dns_name : data.aws_lb.this[0].dns_name
55
nlb_zone_id = var.bootstrap_load_balancer ? aws_lb.this[0].zone_id : data.aws_lb.this[0].zone_id
66

7+
nlb_has_security_groups = var.bootstrap_load_balancer ? false : length(data.aws_lb.this[0].security_groups) > 0
8+
9+
nlb_security_group_ids = local.nlb_has_security_groups ? data.aws_lb.this[0].security_groups : []
10+
11+
nlb_listener_for_egress_rules = concat(
12+
[for l in var.dbx_proxy_listener : { port = l.port, description = "Databricks to NLB to dbx-proxy listener ${l.name}" }],
13+
contains([for l in var.dbx_proxy_listener : l.port], var.dbx_proxy_health_port) ? [] : [{ port = var.dbx_proxy_health_port, description = "NLB to dbx-proxy health checks" }],
14+
)
15+
16+
nlb_sg_egress_rules = local.nlb_has_security_groups ? [
17+
for pair in setproduct(local.nlb_security_group_ids, local.nlb_listener_for_egress_rules, var.subnet_cidrs) : {
18+
security_group_id = pair[0]
19+
description = pair[1].description
20+
port = pair[1].port
21+
cidr = pair[2]
22+
}
23+
] : []
24+
725
allowed_principals = [
826
"arn:aws:iam::565502421330:role/private-connectivity-role-${var.region}"
927
]

terraform/aws/modules/load-balancer/nlb.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ resource "aws_lb" "this" {
1313
tags = var.tags
1414
}
1515

16+
resource "aws_vpc_security_group_egress_rule" "this" {
17+
count = local.nlb_has_security_groups ? length(local.nlb_sg_egress_rules) : 0
18+
19+
security_group_id = local.nlb_sg_egress_rules[count.index].security_group_id
20+
from_port = local.nlb_sg_egress_rules[count.index].port
21+
to_port = local.nlb_sg_egress_rules[count.index].port
22+
ip_protocol = "tcp"
23+
cidr_ipv4 = local.nlb_sg_egress_rules[count.index].cidr
24+
description = local.nlb_sg_egress_rules[count.index].description
25+
}
26+
1627
# Optional: expose the dbx-proxy health port via the NLB so callers can reach it directly
1728
# (e.g. through the PrivateLink endpoint). If the health port is already used as a regular
1829
# listener port, we skip creating this additional listener/TG to avoid a conflict.

terraform/aws/modules/load-balancer/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ variable "subnet_ids" {
3333
type = list(string)
3434
}
3535

36+
variable "subnet_cidrs" {
37+
description = "Subnet CIDR blocks used for NLB security group egress rules."
38+
type = list(string)
39+
}
40+
3641
variable "dbx_proxy_health_port" {
3742
description = "Port on which the dbx-proxy instances expose a TCP health check."
3843
type = number

0 commit comments

Comments
 (0)