Skip to content

Commit 3306e2c

Browse files
committed
Added support for optional IP whitelist (var.ip_whitelist).
1 parent 72f24dd commit 3306e2c

5 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.5.8 (Apr 03, 2025)
2+
* Added support for optional IP whitelist (`var.ip_whitelist`).
3+
14
# 0.5.7 (Mar 31, 2025)
25
* Use SSL certificate from connected subdomain if it created one.
36

https.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "aws_security_group_rule" "lb-https-from-world" {
3636
count = var.enable_https ? 1 : 0
3737

3838
security_group_id = aws_security_group.lb.id
39-
cidr_blocks = ["0.0.0.0/0"]
39+
cidr_blocks = local.allow_ips
4040
type = "ingress"
4141
protocol = "tcp"
4242
from_port = 443

security.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_security_group" "lb" {
77
// This rule is always enabled; when we are listening on https, we still want to force http to https through redirect
88
resource "aws_security_group_rule" "lb-http-from-world" {
99
security_group_id = aws_security_group.lb.id
10-
cidr_blocks = ["0.0.0.0/0"]
10+
cidr_blocks = local.allow_ips
1111
type = "ingress"
1212
protocol = "tcp"
1313
from_port = 80

subdomain.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
data "ns_connection" "subdomain" {
22
name = "subdomain"
3-
type = "subdomain/aws"
43
contract = "subdomain/aws/route53"
54
optional = !var.enable_https
65
}

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,16 @@ Time in seconds that the connection is allowed to be idle.
148148
Default: 60.
149149
EOF
150150
}
151+
152+
variable "ip_whitelist" {
153+
type = list(string)
154+
default = []
155+
description = <<EOF
156+
Specify a list of source IP addresses that can reach this load balancer.
157+
If null or empty, this load balancer allows any IP address to access it.
158+
EOF
159+
}
160+
161+
locals {
162+
allow_ips = (var.ip_whitelist == null || length(var.ip_whitelist) == 0) ? ["0.0.0.0/0"] : var.ip_whitelist
163+
}

0 commit comments

Comments
 (0)