-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsg.tf
150 lines (122 loc) · 4.28 KB
/
nsg.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
resource "oci_core_network_security_group" "public_lb_nsg" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.default_oci_core_vcn.id
display_name = "K3s public LB nsg"
freeform_tags = {
"provisioner" = "terraform"
"environment" = "${var.environment}"
"${var.unique_tag_key}" = "${var.unique_tag_value}"
}
}
resource "oci_core_network_security_group_security_rule" "allow_http_from_all" {
network_security_group_id = oci_core_network_security_group.public_lb_nsg.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow HTTP from all"
source = "0.0.0.0/0"
source_type = "CIDR_BLOCK"
stateless = true
tcp_options {
destination_port_range {
max = var.http_lb_port
min = var.http_lb_port
}
}
}
resource "oci_core_network_security_group_security_rule" "allow_https_from_all" {
network_security_group_id = oci_core_network_security_group.public_lb_nsg.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow HTTPS from all"
source = "0.0.0.0/0"
source_type = "CIDR_BLOCK"
stateless = true
tcp_options {
destination_port_range {
max = var.https_lb_port
min = var.https_lb_port
}
}
}
resource "oci_core_network_security_group_security_rule" "allow_kubeapi_from_all" {
count = var.expose_kubeapi ? 1 : 0
network_security_group_id = oci_core_network_security_group.public_lb_nsg.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow HTTPS from all"
source = join(",", var.public_ips)
source_type = "CIDR_BLOCK"
stateless = true
tcp_options {
destination_port_range {
max = var.kube_api_port
min = var.kube_api_port
}
}
}
resource "oci_core_network_security_group" "lb_to_instances_http" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.default_oci_core_vcn.id
display_name = "Public LB to K3s workers Compute Instances NSG"
freeform_tags = {
"provisioner" = "terraform"
"environment" = "${var.environment}"
"${var.unique_tag_key}" = "${var.unique_tag_value}"
}
}
resource "oci_core_network_security_group_security_rule" "nsg_to_instances_http" {
network_security_group_id = oci_core_network_security_group.lb_to_instances_http.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow HTTP from all"
source = oci_core_network_security_group.public_lb_nsg.id
source_type = "NETWORK_SECURITY_GROUP"
stateless = true
tcp_options {
destination_port_range {
max = var.http_lb_port
min = var.http_lb_port
}
}
}
resource "oci_core_network_security_group_security_rule" "nsg_to_instances_https" {
network_security_group_id = oci_core_network_security_group.lb_to_instances_http.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow HTTPS from all"
source = oci_core_network_security_group.public_lb_nsg.id
source_type = "NETWORK_SECURITY_GROUP"
stateless = true
tcp_options {
destination_port_range {
max = var.https_lb_port
min = var.https_lb_port
}
}
}
resource "oci_core_network_security_group" "lb_to_instances_kubeapi" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.default_oci_core_vcn.id
display_name = "Public LB to K3s master Compute Instances NSG (kubeapi)"
freeform_tags = {
"provisioner" = "terraform"
"environment" = "${var.environment}"
"${var.unique_tag_key}" = "${var.unique_tag_value}"
}
}
resource "oci_core_network_security_group_security_rule" "nsg_to_instances_kubeapi" {
count = var.expose_kubeapi ? 1 : 0
network_security_group_id = oci_core_network_security_group.lb_to_instances_kubeapi.id
direction = "INGRESS"
protocol = 6 # tcp
description = "Allow kubeapi access from my_public_ip_cidr"
source = oci_core_network_security_group.public_lb_nsg.id
source_type = "NETWORK_SECURITY_GROUP"
stateless = true
tcp_options {
destination_port_range {
max = var.kube_api_port
min = var.kube_api_port
}
}
}