-
Notifications
You must be signed in to change notification settings - Fork 31
/
sg-alb.tf
76 lines (63 loc) · 2.13 KB
/
sg-alb.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
resource "aws_security_group" "alb" {
count = var.alb ? 1 : 0
name = "ecs-${var.name}-lb"
description = "SG for ECS ALB"
vpc_id = var.vpc_id
tags = merge(
var.tags,
{
terraform = "true"
Name = "ecs-${var.name}-lb"
},
)
}
resource "aws_security_group_rule" "http_from_world_to_alb" {
count = var.alb && var.alb_http_listener ? 1 : 0
description = "HTTP Redirect ECS 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.alb ? 1 : 0
description = "HTTPS ECS 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" "https_alb_test_listener_from_world_to_alb" {
count = var.alb && var.alb_sg_allow_alb_test_listener && var.alb_test_listener ? 1 : 0
description = "HTTPS ECS ALB Test Listener"
type = "ingress"
from_port = 8443
to_port = 8443
protocol = "tcp"
security_group_id = aws_security_group.alb[0].id
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "to_ecs_nodes" {
count = var.alb ? 1 : 0
description = "Traffic to ECS 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.ecs_nodes.id
}
resource "aws_security_group_rule" "https_from_alb_to_world" {
count = var.alb && var.alb_sg_allow_egress_https_world ? 1 : 0
description = "Traffic from ECS Nodes to HTTPS endpoints"
type = "egress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.alb[0].id
cidr_blocks = ["0.0.0.0/0"]
}