-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_lists.tf
80 lines (76 loc) · 2 KB
/
security_lists.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
locals {
tcp_ports = [
for item in [for x in concat(
[{ port = var.ssh_port, protocol = "tcp" }],
var.minecraft_ports,
var.ssh_knock,
var.minecraft_knock
) : x if x.protocol == "tcp"] :
{
minport = item.port
maxport = item.port
source_cidr = null
protocol = "6" # TCP
stateless = false
}
]
udp_ports = [
for item in [for x in concat(var.ssh_knock, var.minecraft_knock) : x if x.protocol == "udp"] :
{
minport = item.port
maxport = item.port
source_cidr = null
protocol = "17" # TCP
}
]
}
resource "oci_core_security_list" "minecraft" {
#Required
compartment_id = data.oci_identity_compartment.root.id
vcn_id = module.vcn.vcn_id
#Optional
display_name = "Minecraft server firewall"
egress_security_rules {
#Required
destination = "0.0.0.0/0"
protocol = "all"
#Optional
description = "Internet"
}
dynamic "ingress_security_rules" {
iterator = port
for_each = [for x in local.tcp_ports : {
minport = x.minport
maxport = x.maxport
source_cidr = x.source_cidr != null ? x.source_cidr : "0.0.0.0/0"
stateless = x.stateless
}]
content {
protocol = "6" # TCP
source = port.value.source_cidr
stateless = port.value.stateless
tcp_options {
// These values correspond to the destination port range.
min = port.value.minport
max = port.value.maxport
}
}
}
dynamic "ingress_security_rules" {
iterator = port
for_each = [for x in local.udp_ports : {
minport = x.minport
maxport = x.maxport
source_cidr = x.source_cidr != null ? x.source_cidr : "0.0.0.0/0"
}]
content {
protocol = "17" # UDP
source = port.value.source_cidr
udp_options {
// These values correspond to the destination port range.
min = port.value.minport
max = port.value.maxport
}
}
}
}