Skip to content

Commit fa72d55

Browse files
committed
Remove redundand security group rules
I wrongly assummed that they work like a firewall rules and I thought if we make a request to particular port from random port we need to allow connections back. It's not true. It seems security group rules are applied to connection creation not to literal data flow.
1 parent 18d0c10 commit fa72d55

3 files changed

Lines changed: 0 additions & 72 deletions

File tree

aws/mysql/mysql.tf

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ resource "aws_security_group_rule" "db_ingress" {
117117
source_security_group_id = each.value
118118
}
119119

120-
resource "aws_security_group_rule" "db_egress" {
121-
for_each = toset(var.allow_security_group_ids)
122-
123-
security_group_id = aws_security_group.database.id
124-
description = "Egress from mysql"
125-
type = "egress"
126-
protocol = "tcp"
127-
from_port = 0
128-
to_port = 0
129-
source_security_group_id = each.value
130-
}
131-
132120
resource "aws_security_group_rule" "egress_to_db" {
133121
for_each = toset(var.allow_security_group_ids)
134122

@@ -141,18 +129,6 @@ resource "aws_security_group_rule" "egress_to_db" {
141129
source_security_group_id = aws_security_group.database.id
142130
}
143131

144-
resource "aws_security_group_rule" "ingress_from_db" {
145-
for_each = toset(var.allow_security_group_ids)
146-
147-
security_group_id = each.value
148-
description = "Ingress from mysql"
149-
type = "ingress"
150-
protocol = "tcp"
151-
from_port = 0
152-
to_port = 0
153-
source_security_group_id = aws_security_group.database.id
154-
}
155-
156132
resource "random_password" "database" {
157133
length = 20
158134
special = true

aws/postgresql/postgresql.tf

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ resource "aws_security_group_rule" "db_ingress" {
117117
source_security_group_id = each.value
118118
}
119119

120-
resource "aws_security_group_rule" "db_egress" {
121-
for_each = toset(var.allow_security_group_ids)
122-
123-
security_group_id = aws_security_group.database.id
124-
description = "Egress from PostgreSQL"
125-
type = "egress"
126-
protocol = "tcp"
127-
from_port = 0
128-
to_port = 0
129-
source_security_group_id = each.value
130-
}
131-
132120
resource "aws_security_group_rule" "egress_to_db" {
133121
for_each = toset(var.allow_security_group_ids)
134122

@@ -141,18 +129,6 @@ resource "aws_security_group_rule" "egress_to_db" {
141129
source_security_group_id = aws_security_group.database.id
142130
}
143131

144-
resource "aws_security_group_rule" "ingress_from_db" {
145-
for_each = toset(var.allow_security_group_ids)
146-
147-
security_group_id = each.value
148-
description = "Ingress from PostgreSQL"
149-
type = "ingress"
150-
protocol = "tcp"
151-
from_port = 0
152-
to_port = 0
153-
source_security_group_id = aws_security_group.database.id
154-
}
155-
156132
resource "random_password" "database" {
157133
length = 20
158134
special = true

aws/redis/redis.tf

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ resource "aws_security_group_rule" "redis_ingress" {
8282
source_security_group_id = each.value
8383
}
8484

85-
resource "aws_security_group_rule" "redis_egress" {
86-
for_each = toset(var.allow_security_group_ids)
87-
88-
security_group_id = aws_security_group.redis.id
89-
description = "Egress from redis"
90-
type = "egress"
91-
protocol = "tcp"
92-
from_port = 0
93-
to_port = 0
94-
source_security_group_id = each.value
95-
}
96-
9785
resource "aws_security_group_rule" "egress_to_redis" {
9886
for_each = toset(var.allow_security_group_ids)
9987

@@ -106,18 +94,6 @@ resource "aws_security_group_rule" "egress_to_redis" {
10694
source_security_group_id = aws_security_group.redis.id
10795
}
10896

109-
resource "aws_security_group_rule" "ingress_from_redis" {
110-
for_each = toset(var.allow_security_group_ids)
111-
112-
security_group_id = each.value
113-
description = "Ingress from redis"
114-
type = "ingress"
115-
protocol = "tcp"
116-
from_port = 0
117-
to_port = 0
118-
source_security_group_id = aws_security_group.redis.id
119-
}
120-
12197
output "host" {
12298
value = aws_elasticache_cluster.redis.cache_nodes.0.address
12399
}

0 commit comments

Comments
 (0)