-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb-sg.tf
61 lines (50 loc) · 1.72 KB
/
alb-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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
resource "aws_security_group" "alb" {
count = var.lb_type == "ALB" ? 1 : 0
name = "${var.name}-lb"
description = "SG for ALB"
vpc_id = var.vpc_id
tags = {
Name = "${var.name}-lb"
}
}
resource "aws_security_group_rule" "http_from_world_to_alb" {
count = var.lb_type == "ALB" ? 1 : 0
description = "HTTP Redirect ${var.name} ALB"
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.alb[0].id
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "https_from_world_to_alb" {
count = var.lb_type == "ALB" ? 1 : 0
description = "HTTPS ${var.name} ALB"
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.alb[0].id
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "alb_to_nodes" {
count = var.lb_type == "ALB" ? 1 : 0
description = "Traffic to ${var.name} Nodes"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
security_group_id = aws_security_group.alb[0].id
source_security_group_id = aws_security_group.default.id
}
resource "aws_security_group_rule" "from_alb_to_nodes" {
count = var.lb_type == "ALB" ? 1 : 0
description = "from ALB"
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
security_group_id = aws_security_group.default.id
source_security_group_id = aws_security_group.alb[0].id
depends_on = [aws_security_group.default]
}