Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit c3ccf95

Browse files
feat: Add http/https nlb resources (#32)
* feat: Add http/https nlb resources * docs: update terraform docs * chore: Update resource name leggth exceeding 32 characters --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d79c9ba commit c3ccf95

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

clickhouse/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ At this stage the data should be present on all nodes of the cluster given that
9595
| [aws_kms_alias.cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/kms_alias) | resource |
9696
| [aws_kms_key.cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/kms_key) | resource |
9797
| [aws_lb.nlb](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb) | resource |
98+
| [aws_lb_listener.clickhouse_http_nlb_listener](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_listener) | resource |
9899
| [aws_lb_listener.clickhouse_nlb_listener](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_listener) | resource |
100+
| [aws_lb_target_group.clickhouse_http_nlb_target_group](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_target_group) | resource |
99101
| [aws_lb_target_group.clickhouse_nlb_target_group](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_target_group) | resource |
102+
| [aws_lb_target_group_attachment.clickhouse_http_nlb_target_group_attachment](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_target_group_attachment) | resource |
100103
| [aws_lb_target_group_attachment.clickhouse_nlb_target_group_attachment](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/lb_target_group_attachment) | resource |
101104
| [aws_route53_record.clickhouse_cluster](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/route53_record) | resource |
102105
| [aws_route53_record.clickhouse_keeper](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/route53_record) | resource |
@@ -140,6 +143,7 @@ At this stage the data should be present on all nodes of the cluster given that
140143
| [aws_security_group_rule.keeper_outbound](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
141144
| [aws_security_group_rule.keeper_raft](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
142145
| [aws_security_group_rule.keeper_ssh](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
146+
| [aws_security_group_rule.nlb_http_inbound](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
143147
| [aws_security_group_rule.nlb_inbound](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
144148
| [aws_security_group_rule.nlb_to_clickhouse](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/security_group_rule) | resource |
145149
| [aws_volume_attachment.clickhouse](https://registry.terraform.io/providers/hashicorp/aws/5.82.2/docs/resources/volume_attachment) | resource |

clickhouse/nlb.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ resource "aws_lb_listener" "clickhouse_nlb_listener" {
2828
}
2929
}
3030

31+
resource "aws_lb_listener" "clickhouse_http_nlb_listener" {
32+
count = var.enable_nlb ? 1 : 0
33+
load_balancer_arn = aws_lb.nlb[0].arn
34+
port = var.enable_nlb_tls || var.enable_encryption ? var.https_port : var.http_port
35+
protocol = var.enable_nlb_tls ? "TLS" : "TCP"
36+
37+
# Use provided certificate ARN or generated certificate for HTTPS
38+
certificate_arn = var.enable_nlb_tls ? (
39+
var.use_generated_cert ? aws_acm_certificate.nlb[0].arn : var.tls_certificate_arn
40+
) : null
41+
42+
ssl_policy = var.enable_nlb_tls ? "ELBSecurityPolicy-TLS13-1-2-2021-06" : null
43+
44+
default_action {
45+
type = "forward"
46+
target_group_arn = aws_lb_target_group.clickhouse_http_nlb_target_group[0].arn
47+
}
48+
}
49+
3150
resource "aws_lb_target_group" "clickhouse_nlb_target_group" {
3251
count = var.enable_nlb ? 1 : 0
3352
name = "${var.cluster_name}-nlb-tg"
@@ -48,9 +67,36 @@ resource "aws_lb_target_group" "clickhouse_nlb_target_group" {
4867
}
4968
}
5069

70+
resource "aws_lb_target_group" "clickhouse_http_nlb_target_group" {
71+
count = var.enable_nlb ? 1 : 0
72+
name = "${substr(var.cluster_name, 0, 20)}-ch-http-tg"
73+
port = var.enable_encryption ? var.https_port : var.http_port
74+
protocol = "TCP"
75+
vpc_id = module.vpc.vpc_id
76+
target_type = "ip"
77+
78+
health_check {
79+
enabled = true
80+
port = var.enable_encryption ? var.https_port : var.http_port
81+
protocol = "HTTP"
82+
path = "/ping"
83+
healthy_threshold = 3
84+
unhealthy_threshold = 3
85+
interval = 30
86+
timeout = 10
87+
}
88+
}
89+
5190
resource "aws_lb_target_group_attachment" "clickhouse_nlb_target_group_attachment" {
5291
for_each = var.enable_nlb ? module.clickhouse_cluster : {}
5392
target_group_arn = aws_lb_target_group.clickhouse_nlb_target_group[0].arn
5493
target_id = module.clickhouse_cluster[each.key].id
5594
port = var.enable_encryption ? var.tcp_port_secure : var.tcp_port
5695
}
96+
97+
resource "aws_lb_target_group_attachment" "clickhouse_http_nlb_target_group_attachment" {
98+
for_each = var.enable_nlb ? module.clickhouse_cluster : {}
99+
target_group_arn = aws_lb_target_group.clickhouse_http_nlb_target_group[0].arn
100+
target_id = module.clickhouse_cluster[each.key].id
101+
port = var.enable_encryption ? var.https_port : var.http_port
102+
}

clickhouse/sg.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ resource "aws_security_group_rule" "nlb_inbound" {
3333
description = "Allow inbound traffic to NLB"
3434
}
3535

36+
resource "aws_security_group_rule" "nlb_http_inbound" {
37+
count = var.enable_nlb ? 1 : 0
38+
security_group_id = aws_security_group.nlb[0].id
39+
type = "ingress"
40+
from_port = var.enable_encryption ? var.https_port : var.http_port
41+
to_port = var.enable_encryption ? var.https_port : var.http_port
42+
protocol = "tcp"
43+
cidr_blocks = var.nlb_type == "external" ? ["0.0.0.0/0"] : [local.vpc_cidr]
44+
description = "Allow inbound HTTP traffic to ClickHouse NLB"
45+
}
46+
3647
resource "aws_security_group_rule" "nlb_to_clickhouse" {
3748
count = var.enable_nlb ? 1 : 0
3849
security_group_id = aws_security_group.nlb[0].id

0 commit comments

Comments
 (0)