-
Notifications
You must be signed in to change notification settings - Fork 2
/
security_groups.tf
273 lines (249 loc) · 11.3 KB
/
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* The following defines a Security Group for FSx ONTAP that allows the required ports for
* the NFS, CIFS, Kerberos, s3, and iSCSI protocols as well as for SnapMirror, ONTAP API
* and ssh for the source cidr OR the source security group provided in the variables.tf file.
*
* While you don't have to use this SG, one will need to be assigned to the FSx ONTAP file system,
* otherwise it won't be able to communicate with the clients.
*
* - If you wish to skip this resource, set the "create_sg" variable to false and set
* the "security_group_id" to the security group you want to use. Both of these variables
* can be found in the variables.tf file.
*
* - If you wish to use the created Security Group, just be sure to set the cidr_for_sg OR
* source_sg_id varaibles in the variables.tf file. Do not set both or the
* creation of the security group will fail.
*/
resource "aws_security_group" "fsx_sg" {
description = "Allow FSx ONTAP required ports"
count = var.create_sg ? 1 : 0
name_prefix = var.security_group_name_prefix
vpc_id = var.vpc_id
}
resource "aws_vpc_security_group_ingress_rule" "all_icmp" {
description = "Allow ICMP traffic"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = var.cidr_for_sg != "" ? var.cidr_for_sg : null
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = -1
to_port = -1
ip_protocol = "icmp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_tcp" {
description = "Remote procedure call for NFS"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 111
to_port = 111
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_udp" {
description = "Remote procedure call for NFS"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 111
to_port = 111
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "cifs" {
description = "NetBIOS service session for CIFS"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 139
to_port = 139
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "snmp_tcp" {
description = "Simple network management protocol for log collection"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 161
to_port = 162
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "snmp_udp" {
description = "Simple network management protocol for log collection"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 161
to_port = 162
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "smb_cifs" {
description = "Microsoft SMB/CIFS over TCP with NetBIOS framing"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 445
to_port = 445
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_mount_tcp" {
description = "NFS mount"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 635
to_port = 635
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "kerberos" {
description = "Kerberos authentication"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 749
to_port = 749
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_server_daemon" {
description = "NFS server daemon"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 2049
to_port = 2049
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_server_daemon_udp" {
description = "NFS server daemon"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 2049
to_port = 2049
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_lock_daemon" {
description = "NFS lock daemon"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 4045
to_port = 4045
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_lock_daemon_udp" {
description = "NFS lock daemon"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 4045
to_port = 4045
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_status_monitor" {
description = "Status monitor for NFS"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 4046
to_port = 4046
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_status_monitor_udp" {
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
description = "Status monitor for NFS"
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 4046
to_port = 4046
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_rquotad" {
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
description = "Remote quota server for NFS"
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 4049
to_port = 4049
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "iscsi_tcp" {
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
description = "iSCSI"
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 3260
to_port = 3260
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "Snapmirror_Intercluster_communication" {
description = "Snapmirror Intercluster communication"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 11104
to_port = 11104
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "Snapmirror_data_transfer" {
description = "Snapmirror data transfer"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 11105
to_port = 11105
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "nfs_mount_udp" {
description = "NFS mount"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 635
to_port = 635
ip_protocol = "udp"
}
resource "aws_vpc_security_group_ingress_rule" "ssh" {
description = "ssh"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 22
to_port = 22
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_ingress_rule" "s3_and_api" {
description = "Provice acccess to S3 and the ONTAP REST API"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = (var.cidr_for_sg != "" ? var.cidr_for_sg : null)
referenced_security_group_id = (var.source_sg_id != "" ? var.source_sg_id : null)
from_port = 443
to_port = 443
ip_protocol = "tcp"
}
resource "aws_vpc_security_group_egress_rule" "allow_all_traffic" {
description = "Allow all outbound traffic"
count = var.create_sg ? 1 : 0
security_group_id = aws_security_group.fsx_sg[count.index].id
cidr_ipv4 = "0.0.0.0/0" // Allow all output traffic.
ip_protocol = "-1"
}