-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecurity_group.tf
168 lines (146 loc) · 5.28 KB
/
security_group.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# ---------------------------------------------
# Security Group
# ---------------------------------------------
# web security group
resource "aws_security_group" "web_sg" {
name = "${var.project}-${var.environment}-web-sg"
description = "web front security group"
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-${var.environment}-web-sg"
Project = var.project
Env = var.environment
}
}
resource "aws_security_group_rule" "web_in_http" {
security_group_id = aws_security_group.web_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.http_port
to_port = var.http_port
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "web_in_https" {
security_group_id = aws_security_group.web_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.https_port
to_port = var.https_port
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "web_out_tcp3000" {
security_group_id = aws_security_group.web_sg.id
type = "egress"
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
source_security_group_id = aws_security_group.app_sg.id
}
# ---------------------------------------------------------------------------
# app security group
resource "aws_security_group" "app_sg" {
name = "${var.project}-${var.environment}-app-sg"
description = "application server security group"
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-${var.environment}-app-sg"
Project = var.project
Env = var.environment
}
}
resource "aws_security_group_rule" "app_in_tcp3000" {
security_group_id = aws_security_group.app_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
source_security_group_id = aws_security_group.web_sg.id
}
resource "aws_security_group_rule" "app_out_http" {
security_group_id = aws_security_group.app_sg.id
type = "egress"
protocol = "tcp"
from_port = var.http_port
to_port = var.http_port
prefix_list_ids = [data.aws_prefix_list.s3_pl.id]
}
resource "aws_security_group_rule" "app_out_https" {
security_group_id = aws_security_group.app_sg.id
type = "egress"
protocol = "tcp"
from_port = var.https_port
to_port = var.https_port
prefix_list_ids = [data.aws_prefix_list.s3_pl.id]
}
resource "aws_security_group_rule" "app_out_tcp3306" {
security_group_id = aws_security_group.app_sg.id
type = "egress"
protocol = "tcp"
from_port = var.db_port
to_port = var.db_port
source_security_group_id = aws_security_group.db_sg.id
}
# ---------------------------------------------------------------------------
# opmng security group
resource "aws_security_group" "opmng_sg" {
name = "${var.project}-${var.environment}-opmng-sg"
description = "operation management security group"
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-${var.environment}-opmng-sg"
Project = var.project
Env = var.environment
}
}
resource "aws_security_group_rule" "opmng_in_ssh" {
security_group_id = aws_security_group.opmng_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.ssh_port
to_port = var.ssh_port
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "opmng_in_tcp3000" {
security_group_id = aws_security_group.opmng_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "opmng_out_http" {
security_group_id = aws_security_group.opmng_sg.id
type = "egress"
protocol = "tcp"
from_port = var.http_port
to_port = var.http_port
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "opmng_out_https" {
security_group_id = aws_security_group.opmng_sg.id
type = "egress"
protocol = "tcp"
from_port = var.https_port
to_port = var.https_port
cidr_blocks = ["0.0.0.0/0"]
}
# ---------------------------------------------------------------------------
# DB security group
resource "aws_security_group" "db_sg" {
name = "${var.project}-${var.environment}-db-sg"
description = "db server security group"
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-${var.environment}-db-sg"
Project = var.project
Env = var.environment
}
}
resource "aws_security_group_rule" "db_in_tcp3306" {
security_group_id = aws_security_group.db_sg.id
type = "ingress"
protocol = "tcp"
from_port = var.db_port
to_port = var.db_port
source_security_group_id = aws_security_group.app_sg.id
}