-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcn.tf
225 lines (208 loc) · 9.34 KB
/
vcn.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
################################################################################
# Virtual Cloud Networks - VCN, SUBNETS AND NETWORK SECURITY GROUPS
################################################################################
# Create a new VCN
resource "oci_core_vcn" "red5pro_vcn" {
cidr_blocks = [var.vcn_cidr_block]
compartment_id = var.oracle_compartment_id
display_name = "${var.name}-vcn"
is_ipv6enabled = false
lifecycle {
ignore_changes = [dns_label]
}
}
resource "oci_core_internet_gateway" "red5pro_internet_gateway" {
compartment_id = var.oracle_compartment_id
vcn_id = oci_core_vcn.red5pro_vcn.id
enabled = true
display_name = "${var.name}-internet-gateway"
}
resource "oci_core_route_table" "red5pro_route_table" {
compartment_id = var.oracle_compartment_id
vcn_id = oci_core_vcn.red5pro_vcn.id
display_name = "${var.name}-route-table"
route_rules {
network_entity_id = oci_core_internet_gateway.red5pro_internet_gateway.id
description = "Default IPv4 Route Rule"
destination = "0.0.0.0/0"
}
}
# Default VCN Network Security List
resource "oci_core_security_list" "red5pro_security_list" {
compartment_id = var.oracle_compartment_id
display_name = "${var.name}-security-list"
vcn_id = local.vcn_id
egress_security_rules {
protocol = "all"
destination = "0.0.0.0/0"
}
}
# Create a new Public Subnet
resource "oci_core_subnet" "red5pro_vcn_subnet_public" {
cidr_block = var.subnet_cidr_block
compartment_id = var.oracle_compartment_id
vcn_id = oci_core_vcn.red5pro_vcn.id
display_name = "${var.name}-public-subnet"
prohibit_public_ip_on_vnic = false
route_table_id = oci_core_route_table.red5pro_route_table.id
security_list_ids = [oci_core_security_list.red5pro_security_list.id]
lifecycle {
ignore_changes = [dns_label]
}
}
resource "oci_core_route_table_attachment" "red5pro_route_table_attachment" {
subnet_id = oci_core_subnet.red5pro_vcn_subnet_public.id
route_table_id = oci_core_route_table.red5pro_route_table.id
}
# Network Security group for Standalone Red5Pro server
resource "oci_core_network_security_group" "red5pro_standalone_network_security_group" {
count = local.standalone ? 1 : 0
compartment_id = var.oracle_compartment_id
vcn_id = local.vcn_id
display_name = "${var.name}-standalone-nsg"
}
resource "oci_core_network_security_group_security_rule" "red5pro_standalone_nsg_security_rule_ingress" {
count = local.standalone ? length(var.network_security_group_standalone_ingress) : 0
network_security_group_id = oci_core_network_security_group.red5pro_standalone_network_security_group[0].id
direction = "INGRESS"
protocol = var.network_security_group_standalone_ingress[count.index].protocol
description = var.network_security_group_standalone_ingress[count.index].description
source = var.network_security_group_standalone_ingress[count.index].source
source_type = "CIDR_BLOCK"
stateless = false
dynamic "tcp_options" {
for_each = var.network_security_group_standalone_ingress[count.index].protocol == "6" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_standalone_ingress[count.index].port_min
max = var.network_security_group_standalone_ingress[count.index].port_max
}
}
}
dynamic "udp_options" {
for_each = var.network_security_group_standalone_ingress[count.index].protocol == "17" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_standalone_ingress[count.index].port_min
max = var.network_security_group_standalone_ingress[count.index].port_max
}
}
}
# lifecycle {
# ignore_changes = [direction, protocol, source, source_type, tcp_options]
# }
}
# Network Security group for Stream Manager
resource "oci_core_network_security_group" "red5pro_stream_manager_network_security_group" {
count = local.cluster_or_autoscale ? 1 : 0
compartment_id = var.oracle_compartment_id
vcn_id = local.vcn_id
display_name = "${var.name}-sm2-nsg"
}
resource "oci_core_network_security_group_security_rule" "red5pro_stream_manager_nsg_security_rule_ingress" {
count = local.cluster_or_autoscale ? length(var.network_security_group_stream_manager_ingress) : 0
network_security_group_id = oci_core_network_security_group.red5pro_stream_manager_network_security_group[0].id
direction = "INGRESS"
protocol = var.network_security_group_stream_manager_ingress[count.index].protocol
description = var.network_security_group_stream_manager_ingress[count.index].description
source = var.network_security_group_stream_manager_ingress[count.index].source
source_type = "CIDR_BLOCK"
stateless = false
dynamic "tcp_options" {
for_each = var.network_security_group_stream_manager_ingress[count.index].protocol == "6" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_stream_manager_ingress[count.index].port_min
max = var.network_security_group_stream_manager_ingress[count.index].port_max
}
}
}
dynamic "udp_options" {
for_each = var.network_security_group_stream_manager_ingress[count.index].protocol == "17" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_stream_manager_ingress[count.index].port_min
max = var.network_security_group_stream_manager_ingress[count.index].port_max
}
}
}
# lifecycle {
# ignore_changes = [direction, protocol, source, source_type, tcp_options]
# }
}
# Network Security group for SM Nodes
resource "oci_core_network_security_group" "red5pro_node_network_security_group" {
count = local.cluster_or_autoscale ? 1 : 0
compartment_id = var.oracle_compartment_id
vcn_id = local.vcn_id
display_name = "${var.name}-node-nsg"
}
resource "oci_core_network_security_group_security_rule" "red5pro_node_nsg_security_rule_ingress" {
count = local.cluster_or_autoscale ? length(var.network_security_group_node_ingress) : 0
network_security_group_id = oci_core_network_security_group.red5pro_node_network_security_group[0].id
direction = "INGRESS"
protocol = var.network_security_group_node_ingress[count.index].protocol
description = var.network_security_group_node_ingress[count.index].description
source = var.network_security_group_node_ingress[count.index].source
source_type = "CIDR_BLOCK"
stateless = false
dynamic "tcp_options" {
for_each = var.network_security_group_node_ingress[count.index].protocol == "6" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_node_ingress[count.index].port_min
max = var.network_security_group_node_ingress[count.index].port_max
}
}
}
dynamic "udp_options" {
for_each = var.network_security_group_node_ingress[count.index].protocol == "17" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_node_ingress[count.index].port_min
max = var.network_security_group_node_ingress[count.index].port_max
}
}
}
# lifecycle {
# ignore_changes = [direction, protocol, source, source_type, tcp_options]
# }
}
# Network Security group for Kafka server
resource "oci_core_network_security_group" "red5pro_kafka_network_security_group" {
count = local.kafka_standalone_instance ? 1 : 0
compartment_id = var.oracle_compartment_id
vcn_id = local.vcn_id
display_name = "${var.name}-kafka-nsg"
}
resource "oci_core_network_security_group_security_rule" "red5pro_kafka_nsg_security_rule_ingress" {
count = local.kafka_standalone_instance ? length(var.network_security_group_kafka_ingress) : 0
network_security_group_id = oci_core_network_security_group.red5pro_kafka_network_security_group[0].id
direction = "INGRESS"
protocol = var.network_security_group_kafka_ingress[count.index].protocol
description = var.network_security_group_kafka_ingress[count.index].description
source = var.network_security_group_kafka_ingress[count.index].source
source_type = "CIDR_BLOCK"
stateless = false
dynamic "tcp_options" {
for_each = var.network_security_group_kafka_ingress[count.index].protocol == "6" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_kafka_ingress[count.index].port_min
max = var.network_security_group_kafka_ingress[count.index].port_max
}
}
}
dynamic "udp_options" {
for_each = var.network_security_group_kafka_ingress[count.index].protocol == "17" ? [1] : []
content {
destination_port_range {
min = var.network_security_group_kafka_ingress[count.index].port_min
max = var.network_security_group_kafka_ingress[count.index].port_max
}
}
}
# lifecycle {
# ignore_changes = [direction, protocol, source, source_type, tcp_options]
# }
}