-
Notifications
You must be signed in to change notification settings - Fork 2
/
sg.tf
43 lines (38 loc) · 1.23 KB
/
sg.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
resource "aws_security_group" "redis" {
name = var.name
vpc_id = var.vpc_id
tags = {
Name = var.name
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group_rule" "redis_inbound_cidrs" {
count = length(var.allow_cidrs) != 0 ? 1 : 0
type = "ingress"
from_port = var.port
to_port = var.port
protocol = "tcp"
cidr_blocks = var.allow_cidrs
security_group_id = aws_security_group.redis.id
description = "From CIDR ${join(", ", var.allow_cidrs)}"
}
resource "aws_security_group_rule" "redis_inbound_sg" {
count = length(var.allow_security_group_ids)
type = "ingress"
from_port = var.port
to_port = var.port
protocol = "tcp"
source_security_group_id = var.allow_security_group_ids[count.index]
security_group_id = aws_security_group.redis.id
description = "Allow access"
}
resource "aws_security_group_rule" "outbound" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
security_group_id = aws_security_group.redis.id
cidr_blocks = ["0.0.0.0/0"]
}