Skip to content

Commit

Permalink
feat: 🎸 add new eks subnets to rds security groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-williams committed Sep 11, 2024
1 parent 356ff82 commit 8752b36
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ data "aws_subnet" "private" {
id = each.value
}

data "aws_subnets" "eks_private" {
filter {
name = "vpc-id"
values = [data.aws_vpc.this.id]
}

tags = {
SubnetType = "EKS-Private"
}
}

data "aws_subnet" "eks_private" {
for_each = toset(data.aws_subnets.eks_private.ids)
id = each.value
}

########################
# Generate identifiers #
########################
Expand Down Expand Up @@ -123,18 +139,24 @@ resource "aws_security_group" "rds-sg" {
# cyclic dependency. Rather than resorting to `aws_security_group_rule` which
# is not ideal for managing rules, we will simply allow traffic to all ports.
# This does not compromise security as the instance only listens on one port.
ingress {
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [for s in data.aws_subnet.private : s.cidr_block]
cidr_blocks = concat(
[for s in data.aws_subnet.private : s.cidr_block],
[for s in data.aws_subnet.eks_private : s.cidr_block]
)
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [for s in data.aws_subnet.private : s.cidr_block]
cidr_blocks = concat(
[for s in data.aws_subnet.private : s.cidr_block],
[for s in data.aws_subnet.eks_private : s.cidr_block]
)
}
}

Expand Down

0 comments on commit 8752b36

Please sign in to comment.