-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.tf
101 lines (83 loc) · 2.29 KB
/
security.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Security Groups
# Internet to ALB
resource "aws_security_group" "fphs_lb" {
name = "${local.name}-alb"
description = "Allow access to port 443 only"
vpc_id = aws_vpc.fphs.id
ingress {
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = local.common_tags
}
# ALB TO ECS
resource "aws_security_group" "fphs_ecs" {
name = "${local.name}-ecs"
description = "Allow inbound access from ALB only"
vpc_id = aws_vpc.fphs.id
ingress {
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
security_groups = [aws_security_group.fphs_lb.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = local.common_tags
}
# ECS to Elasticache
resource "aws_security_group" "fphs_elasticache" {
name = "${local.name}-elasticache"
description = "Allow inbound access from ECS only"
vpc_id = aws_vpc.fphs.id
ingress {
protocol = "tcp"
from_port = local.secrets["cache"]["port"]
to_port = local.secrets["cache"]["port"]
security_groups = [aws_security_group.fphs_ecs.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = local.common_tags
}
# ECS to RDS
resource "aws_security_group" "fphs_rds" {
name = "${local.name}-rds"
description = "Allow inbound access from ECS only"
vpc_id = aws_vpc.fphs.id
ingress {
protocol = "tcp"
from_port = local.secrets["db"]["port"]
to_port = local.secrets["db"]["port"]
security_groups = [aws_security_group.fphs_ecs.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = local.common_tags
}