Skip to content

Commit 95ead3d

Browse files
feat(security-groups): add ingress prefix lists (#205)
* feat(security-groups): add ingress prefix lists Add new variable: allowed_prefix_list_ids Add new resource: aws_security_group_rule.ingress_cidr_blocks Signed-off-by: Viktoras Draugelis <viktoras.draugelis@oag.com> * chore(security-group): replace join with one for target sg id Co-authored-by: Veronika Gnilitska <30597968+gberenice@users.noreply.github.com> --------- Signed-off-by: Viktoras Draugelis <viktoras.draugelis@oag.com> Co-authored-by: Veronika Gnilitska <30597968+gberenice@users.noreply.github.com>
1 parent aeb0f06 commit 95ead3d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
215215
security_group_id = join("", aws_security_group.default[*].id)
216216
}
217217

218+
resource "aws_security_group_rule" "ingress_prefix_lists" {
219+
count = module.this.enabled && length(var.allowed_prefix_list_ids) > 0 ? 1 : 0
220+
221+
description = "Allow inbound traffic from prefix lists"
222+
type = "ingress"
223+
from_port = var.database_port
224+
to_port = var.database_port
225+
protocol = "tcp"
226+
prefix_list_ids = var.allowed_prefix_list_ids
227+
security_group_id = one(aws_security_group.default[*].id)
228+
}
229+
218230
resource "aws_security_group_rule" "egress" {
219231
count = module.this.enabled ? 1 : 0
220232
description = "Allow all egress traffic"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ variable "allowed_cidr_blocks" {
2222
description = "The whitelisted CIDRs which to allow `ingress` traffic to the DB instance"
2323
}
2424

25+
variable "allowed_prefix_list_ids" {
26+
type = list(string)
27+
default = []
28+
description = "The list of prefix list IDs from which to allow `ingress` traffic to the DB instance"
29+
}
30+
2531
variable "associate_security_group_ids" {
2632
type = list(string)
2733
default = []

0 commit comments

Comments
 (0)