Skip to content

Commit f9918a5

Browse files
make sg better
1 parent 7193c33 commit f9918a5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

security_groups.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ resource "aws_security_group" "redis_security_group" {
88
}
99
}
1010

11-
resource "aws_security_group_rule" "redis_ingress" {
12-
count = length(var.allowed_security_groups)
11+
resource "aws_security_group_rule" "redis_inbound_from_sg" {
12+
for_each = { for security_group_id in var.allow_security_group_ids : security_group_id.name => security_group_id }
1313
type = "ingress"
1414
from_port = var.redis_port
1515
to_port = var.redis_port
1616
protocol = "tcp"
17-
source_security_group_id = element(var.allowed_security_groups, count.index)
17+
source_security_group_id = each.value.security_group_id
1818
security_group_id = aws_security_group.redis_security_group.id
19+
description = try(each.value.description, "From ${each.value.security_group_id}")
1920
}
2021

2122
resource "aws_security_group_rule" "redis_networks_ingress" {

variables.tf

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ variable "apply_immediately" {
2323
variable "allowed_cidr" {
2424
description = "A list of Security Group ID's to allow access to."
2525
type = list(string)
26-
default = ["127.0.0.1/32"]
26+
default = []
2727
}
2828

29-
variable "allowed_security_groups" {
30-
description = "A list of Security Group ID's to allow access to."
31-
type = list(string)
29+
variable "allow_security_group_ids" {
30+
type = list(object({
31+
security_group_id = string
32+
description = string
33+
name = string
34+
}))
35+
description = "List of Security Group IDs to allow connection to."
3236
default = []
3337
}
3438

0 commit comments

Comments
 (0)