-
Notifications
You must be signed in to change notification settings - Fork 1
/
002_security_groups.tf
221 lines (168 loc) · 7.17 KB
/
002_security_groups.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
## ------------------------------------------------------------------------------------
## NOTE!
## ------------------------------------------------------------------------------------
# This is less elegant than using a for-each construct but I think it's easier to maintain.
# YMMV - A rewrite could make things cleaner.
## ------------------------------------------------------------------------------------
## Instance Connect Endpoint Controls
## ------------------------------------------------------------------------------------
module "tower_eice_ingress_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_eice_sg"
description = "Allowed ingress CIDRS EC2 Instance Connect endpoint."
vpc_id = local.vpc_id
ingress_cidr_blocks = var.sg_ssh_cidrs
ingress_rules = ["ssh-tcp"]
}
module "tower_eice_egress_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_ec2_egress_sg"
description = "Allowed egress CIDRS EC2 Instance Connect endpoint."
vpc_id = local.vpc_id
egress_rules = var.sg_egress_eice
}
## ------------------------------------------------------------------------------------
## EC2 Controls
## ------------------------------------------------------------------------------------
module "tower_ec2_ssh_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_ec2_ssh_sg"
description = "Allowed SSH ingress to EC2 instance (EICE only)."
vpc_id = local.vpc_id
ingress_cidr_blocks = var.sg_ssh_cidrs
ingress_rules = ["ssh-tcp"]
}
module "tower_ec2_egress_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_ec2_egress_sg"
description = "Tower EC2 host egress."
vpc_id = local.vpc_id
ingress_cidr_blocks = var.sg_ingress_cidrs
egress_rules = var.sg_egress_tower_ec2
}
module "tower_ec2_direct_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_ec2_direct_sg"
description = "Direct HTTP to Tower EC2 host."
vpc_id = local.vpc_id
ingress_cidr_blocks = var.sg_ingress_cidrs
ingress_rules = ["https-443-tcp", "http-80-tcp", "splunk-web-tcp"]
}
module "tower_ec2_direct_connect_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
count = var.flag_enable_data_studio == true ? 1 : 0
name = "${local.global_prefix}_ec2_direct_connect_sg"
description = "Direct HTTP to Tower EC2 host when Connect active."
vpc_id = local.vpc_id
ingress_with_cidr_blocks = local.tower_ec2_direct_connect_sg_final
}
module "tower_ec2_alb_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_ec2_alb_sg"
description = "ALB HTTP to Tower EC2 host."
vpc_id = local.vpc_id
computed_ingress_with_source_security_group_id = [
{
rule = "splunk-web-tcp"
source_security_group_id = module.tower_alb_sg.security_group_id
}
]
number_of_computed_ingress_with_source_security_group_id = 1
}
## ------------------------------------------------------------------------------------
## ALB Controls
## ------------------------------------------------------------------------------------
module "tower_alb_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_alb_sg"
description = "HTTP to Tower ALB instance."
vpc_id = local.vpc_id
ingress_cidr_blocks = local.alb_ingress_cidrs #var.sg_ingress_cidrs
ingress_rules = ["https-443-tcp", "http-80-tcp"]
egress_rules = var.sg_egress_tower_alb
}
module "tower_ec2_alb_connect_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
count = var.flag_enable_data_studio == true ? 1 : 0
name = "${local.global_prefix}_ec2_alb_connect_sg"
description = "Direct HTTP to Tower EC2 host when Connect active."
vpc_id = local.vpc_id
# computed_ingress_with_cidr_blocks = local.tower_ec2_alb_connect_sg_final
# computed_ingress_with_cidr_blocks = local.tower_ec2_alb_connect_sg_final
computed_ingress_with_source_security_group_id= local.tower_ec2_alb_connect_sg_final
number_of_computed_ingress_with_source_security_group_id = 1
}
## ------------------------------------------------------------------------------------
## DB Controls
## ------------------------------------------------------------------------------------
module "tower_db_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_rds_sg"
description = "Security group for Tower RDS instance."
vpc_id = local.vpc_id
computed_ingress_with_source_security_group_id = [
{
rule = "mysql-tcp"
source_security_group_id = module.tower_ec2_egress_sg.security_group_id
}
]
number_of_computed_ingress_with_source_security_group_id = 1
}
## ------------------------------------------------------------------------------------
## AWS Batch Security Groups
## ------------------------------------------------------------------------------------
module "tower_batch_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_batch_sg"
description = "Security group for Tower Batch instance."
vpc_id = local.vpc_id
egress_rules = var.sg_egress_batch_ec2
computed_ingress_with_source_security_group_id = [
{
rule = "ssh-tcp"
source_security_group_id = module.tower_ec2_egress_sg.security_group_id
}
]
number_of_computed_ingress_with_source_security_group_id = 1
}
## ------------------------------------------------------------------------------------
## Elasticache (Redis) Controls
## ------------------------------------------------------------------------------------
module "tower_redis_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_redis_sg"
description = "Security group for Tower Elasticache instance."
vpc_id = local.vpc_id
computed_ingress_with_source_security_group_id = [
{
rule = "redis-tcp"
source_security_group_id = module.tower_ec2_egress_sg.security_group_id
}
]
number_of_computed_ingress_with_source_security_group_id = 1
}
## ------------------------------------------------------------------------------------
## Gateway & Interface Endpoint Controls
## ------------------------------------------------------------------------------------
module "tower_interface_endpoint_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
name = "${local.global_prefix}_interface_sg"
description = "Allowed ingress on VPC endpoints in Tower Subnet."
vpc_id = local.vpc_id
ingress_cidr_blocks = [var.vpc_new_cidr_range]
ingress_rules = ["all-all"]
egress_rules = var.sg_egress_interface_endpoint
}