forked from marcelo-ochoa/oci-swarm-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security-lists.tf
154 lines (128 loc) · 4.4 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
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
# Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
resource "oci_core_security_list" "oci_swarm_security_list" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_virtual_network.oci_swarm_main_vcn.id
display_name = "oci-swarm-main-${random_string.deploy_id.result}"
freeform_tags = local.common_tags
dynamic "ingress_security_rules" {
for_each = var.create_secondary_vcn ? [1] : []
content {
protocol = local.all_protocols
source = lookup(var.network_cidrs, "LB-VCN-CIDR")
}
}
ingress_security_rules {
protocol = local.all_protocols
source = lookup(var.network_cidrs, "MAIN-SUBNET-REGIONAL-CIDR")
stateless = true
}
ingress_security_rules {
protocol = local.tcp_protocol_number
source = lookup(var.network_cidrs, (var.instance_visibility == "Private") ? "MAIN-VCN-CIDR" : "ALL-CIDR")
tcp_options {
max = local.http_port_number
min = local.http_port_number
}
}
ingress_security_rules {
protocol = local.tcp_protocol_number
source = lookup(var.network_cidrs, (var.instance_visibility == "Private") ? "MAIN-VCN-CIDR" : "ALL-CIDR")
tcp_options {
max = local.ssh_port_number
min = local.ssh_port_number
}
}
ingress_security_rules {
protocol = local.tcp_protocol_number
source = lookup(var.network_cidrs, (var.instance_visibility == "Private") ? "MAIN-VCN-CIDR" : "ALL-CIDR")
tcp_options {
max = local.https_port_number
min = local.https_port_number
}
}
dynamic "egress_security_rules" {
for_each = var.create_secondary_vcn ? [1] : []
content {
protocol = local.all_protocols
destination = lookup(var.network_cidrs, "LB-VCN-CIDR")
}
}
egress_security_rules {
protocol = local.all_protocols
destination = lookup(var.network_cidrs, "MAIN-SUBNET-REGIONAL-CIDR")
stateless = true
}
egress_security_rules {
protocol = local.all_protocols
destination = lookup(var.network_cidrs, (var.instance_visibility == "Private") ? "MAIN-VCN-CIDR" : "ALL-CIDR")
}
egress_security_rules {
protocol = local.all_protocols
destination = lookup(data.oci_core_services.all_services.services[0], "cidr_block")
destination_type = "SERVICE_CIDR_BLOCK"
}
}
resource "oci_core_security_list" "oci_swarm_lb_security_list" {
compartment_id = (var.lb_compartment_ocid != "") ? var.lb_compartment_ocid : var.compartment_ocid
vcn_id = var.create_secondary_vcn ? oci_core_virtual_network.oci_swarm_lb_vcn[0].id : oci_core_virtual_network.oci_swarm_main_vcn.id
display_name = "oci-swarm-lb-${random_string.deploy_id.result}"
freeform_tags = local.common_tags
dynamic "ingress_security_rules" {
for_each = var.create_secondary_vcn ? [1] : []
content {
protocol = local.all_protocols
source = lookup(var.network_cidrs, "MAIN-VCN-CIDR")
}
}
ingress_security_rules {
protocol = local.all_protocols
source = lookup(var.network_cidrs, "ALL-CIDR")
stateless = true
}
ingress_security_rules {
protocol = local.tcp_protocol_number
source = lookup(var.network_cidrs, "ALL-CIDR")
tcp_options {
max = local.http_port_number
min = local.http_port_number
}
}
ingress_security_rules {
protocol = local.tcp_protocol_number
source = lookup(var.network_cidrs, "ALL-CIDR")
tcp_options {
max = local.https_port_number
min = local.https_port_number
}
}
dynamic "egress_security_rules" {
for_each = var.create_secondary_vcn ? [1] : []
content {
protocol = local.all_protocols
destination = lookup(var.network_cidrs, "MAIN-VCN-CIDR")
}
}
egress_security_rules {
protocol = local.all_protocols
destination = lookup(var.network_cidrs, "ALL-CIDR")
stateless = true
}
egress_security_rules {
protocol = local.tcp_protocol_number
destination = lookup(var.network_cidrs, "MAIN-SUBNET-REGIONAL-CIDR")
tcp_options {
max = local.microservices_port_number
min = local.microservices_port_number
}
}
}
locals {
http_port_number = "80"
https_port_number = "443"
microservices_port_number = "80"
ssh_port_number = "22"
tcp_protocol_number = "6"
all_protocols = "all"
}