Skip to content

Commit 280d3dd

Browse files
authored
745 update grabdish terraform (#747)
* Reading the Kubernetes version from main_var.tf and updated the version to 1.27.2 for infra env. * updates OKE ver and provider * Linting * More Ignores for Testing * Variablise kubernetes_version * Linting
1 parent 243bdee commit 280d3dd

File tree

4 files changed

+67
-61
lines changed

4 files changed

+67
-61
lines changed

infra/k8s/oke/terraform/containerengine.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
resource "oci_containerengine_cluster" "oke" {
55
#Required
6-
compartment_id = var.ociCompartmentOcid
6+
compartment_id = var.ociCompartmentOcid
77
endpoint_config {
88
is_public_ip_enabled = "true"
99
nsg_ids = [
1010
]
1111
subnet_id = oci_core_subnet.endpoint.id
1212
}
13-
kubernetes_version = "v1.26.2"
13+
kubernetes_version = var.kubernetes_version
1414
name = "grabdish"
1515
vcn_id = data.oci_core_vcn.vcn.id
1616
#Optional
@@ -37,7 +37,7 @@ resource "oci_containerengine_cluster" "oke" {
3737
resource "oci_containerengine_node_pool" "okell_node_pool" {
3838
cluster_id = oci_containerengine_cluster.oke.id
3939
compartment_id = var.ociCompartmentOcid
40-
kubernetes_version = "v1.26.2"
40+
kubernetes_version = var.kubernetes_version
4141
name = "Pool"
4242
node_shape = "VM.Standard.E2.1"
4343
node_config_details {
@@ -58,8 +58,8 @@ data "oci_containerengine_node_pool_option" "okell_node_pool_option" {
5858
}
5959

6060
locals {
61-
all_sources = data.oci_containerengine_node_pool_option.okell_node_pool_option.sources
62-
oracle_linux_images = [for source in local.all_sources : source.image_id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",source.source_name)) > 0]
61+
all_sources = data.oci_containerengine_node_pool_option.okell_node_pool_option.sources
62+
oracle_linux_images = [for source in local.all_sources : source.image_id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*", source.source_name)) > 0]
6363
}
6464

6565
output "oke_ocid" {

infra/k8s/oke/terraform/core.tf

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
//Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
locals {
5-
endpoint_cidr_block = "10.0.0.0/28"
6-
nodepool_cidr_block = "10.0.10.0/24"
7-
svclb_cidr_block = "10.0.20.0/24"
5+
endpoint_cidr_block = "10.0.0.0/28"
6+
nodepool_cidr_block = "10.0.10.0/24"
7+
svclb_cidr_block = "10.0.20.0/24"
88
}
99

1010
data "oci_core_vcn" "vcn" {
11-
#Required
12-
vcn_id = var.vcnOcid
11+
#Required
12+
vcn_id = var.vcnOcid
1313
}
1414

1515
data "oci_core_nat_gateways" "ngws" {
16-
compartment_id = var.ociCompartmentOcid
17-
vcn_id = data.oci_core_vcn.vcn.id
16+
compartment_id = var.ociCompartmentOcid
17+
vcn_id = data.oci_core_vcn.vcn.id
1818
}
1919

2020
data "oci_core_service_gateways" "sgs" {
21-
compartment_id = var.ociCompartmentOcid
22-
vcn_id = data.oci_core_vcn.vcn.id
21+
compartment_id = var.ociCompartmentOcid
22+
vcn_id = data.oci_core_vcn.vcn.id
2323
}
2424

25-
resource oci_core_route_table private {
25+
resource "oci_core_route_table" "private" {
2626
compartment_id = var.ociCompartmentOcid
27-
display_name = "private"
27+
display_name = "private"
2828
freeform_tags = {
2929
}
3030
route_rules {
@@ -43,55 +43,55 @@ resource oci_core_route_table private {
4343
}
4444

4545
resource "oci_core_subnet" "endpoint" {
46-
cidr_block = local.endpoint_cidr_block
47-
compartment_id = var.ociCompartmentOcid
48-
vcn_id = data.oci_core_vcn.vcn.id
49-
security_list_ids = [oci_core_security_list.endpoint.id]
50-
display_name = "Endpoint"
46+
cidr_block = local.endpoint_cidr_block
47+
compartment_id = var.ociCompartmentOcid
48+
vcn_id = data.oci_core_vcn.vcn.id
49+
security_list_ids = [oci_core_security_list.endpoint.id]
50+
display_name = "Endpoint"
5151
prohibit_public_ip_on_vnic = "false"
52-
route_table_id = data.oci_core_vcn.vcn.default_route_table_id
53-
dns_label = "endpoint"
52+
route_table_id = data.oci_core_vcn.vcn.default_route_table_id
53+
dns_label = "endpoint"
5454
}
5555

5656
resource "oci_core_subnet" "nodepool" {
57-
cidr_block = local.nodepool_cidr_block
58-
compartment_id = var.ociCompartmentOcid
59-
vcn_id = data.oci_core_vcn.vcn.id
60-
security_list_ids = [oci_core_security_list.nodepool.id]
61-
display_name = "Node Pool"
57+
cidr_block = local.nodepool_cidr_block
58+
compartment_id = var.ociCompartmentOcid
59+
vcn_id = data.oci_core_vcn.vcn.id
60+
security_list_ids = [oci_core_security_list.nodepool.id]
61+
display_name = "Node Pool"
6262
prohibit_public_ip_on_vnic = "true"
63-
route_table_id = oci_core_route_table.private.id
64-
dns_label = "nodepool"
63+
route_table_id = oci_core_route_table.private.id
64+
dns_label = "nodepool"
6565
}
6666

6767
resource "oci_core_subnet" "svclb" {
68-
cidr_block = local.svclb_cidr_block
69-
compartment_id = var.ociCompartmentOcid
70-
vcn_id = data.oci_core_vcn.vcn.id
71-
security_list_ids = [data.oci_core_vcn.vcn.default_security_list_id]
72-
display_name = "Service Load Balancer"
73-
route_table_id = data.oci_core_vcn.vcn.default_route_table_id
74-
dhcp_options_id = data.oci_core_vcn.vcn.default_dhcp_options_id
68+
cidr_block = local.svclb_cidr_block
69+
compartment_id = var.ociCompartmentOcid
70+
vcn_id = data.oci_core_vcn.vcn.id
71+
security_list_ids = [data.oci_core_vcn.vcn.default_security_list_id]
72+
display_name = "Service Load Balancer"
73+
route_table_id = data.oci_core_vcn.vcn.default_route_table_id
74+
dhcp_options_id = data.oci_core_vcn.vcn.default_dhcp_options_id
7575
prohibit_public_ip_on_vnic = "false"
76-
dns_label = "svclb"
76+
dns_label = "svclb"
7777
}
7878

79-
resource oci_core_security_list nodepool {
79+
resource "oci_core_security_list" "nodepool" {
8080
compartment_id = var.ociCompartmentOcid
81-
display_name = "Node Pool"
81+
display_name = "Node Pool"
8282
egress_security_rules {
8383
description = "Allow pods on one worker node to communicate with pods on other worker nodes"
8484
destination = local.nodepool_cidr_block
8585
destination_type = "CIDR_BLOCK"
86-
protocol = "all"
87-
stateless = "false"
86+
protocol = "all"
87+
stateless = "false"
8888
}
8989
egress_security_rules {
9090
description = "Access to Kubernetes API Endpoint"
9191
destination = local.endpoint_cidr_block
9292
destination_type = "CIDR_BLOCK"
93-
protocol = "6"
94-
stateless = "false"
93+
protocol = "6"
94+
stateless = "false"
9595
tcp_options {
9696
max = "6443"
9797
min = "6443"
@@ -101,8 +101,8 @@ resource oci_core_security_list nodepool {
101101
description = "Kubernetes worker to control plane communication"
102102
destination = local.endpoint_cidr_block
103103
destination_type = "CIDR_BLOCK"
104-
protocol = "6"
105-
stateless = "false"
104+
protocol = "6"
105+
stateless = "false"
106106
tcp_options {
107107
max = "12250"
108108
min = "12250"
@@ -123,8 +123,8 @@ resource oci_core_security_list nodepool {
123123
description = "Allow nodes to communicate with OKE to ensure correct start-up and continued functioning (0)"
124124
destination = data.oci_core_services.services.services.0.cidr_block
125125
destination_type = "SERVICE_CIDR_BLOCK"
126-
protocol = "6"
127-
stateless = "false"
126+
protocol = "6"
127+
stateless = "false"
128128
tcp_options {
129129
max = "443"
130130
min = "443"
@@ -145,9 +145,9 @@ resource oci_core_security_list nodepool {
145145
description = "Worker Nodes access to Internet"
146146
destination = "0.0.0.0/0"
147147
destination_type = "CIDR_BLOCK"
148-
protocol = "all"
149-
stateless = "false"
150-
}
148+
protocol = "all"
149+
stateless = "false"
150+
}
151151
freeform_tags = {
152152
}
153153
ingress_security_rules {
@@ -189,15 +189,15 @@ resource oci_core_security_list nodepool {
189189
vcn_id = data.oci_core_vcn.vcn.id
190190
}
191191

192-
resource oci_core_security_list endpoint {
192+
resource "oci_core_security_list" "endpoint" {
193193
compartment_id = var.ociCompartmentOcid
194-
display_name = "Endpoint"
194+
display_name = "Endpoint"
195195
egress_security_rules {
196196
description = "Allow Kubernetes Control Plane to communicate with OKE"
197197
destination = data.oci_core_services.services.services.0.cidr_block
198198
destination_type = "SERVICE_CIDR_BLOCK"
199-
protocol = "6"
200-
stateless = "false"
199+
protocol = "6"
200+
stateless = "false"
201201
tcp_options {
202202
max = "443"
203203
min = "443"
@@ -207,8 +207,8 @@ resource oci_core_security_list endpoint {
207207
description = "All traffic to worker nodes"
208208
destination = local.nodepool_cidr_block
209209
destination_type = "CIDR_BLOCK"
210-
protocol = "6"
211-
stateless = "false"
210+
protocol = "6"
211+
stateless = "false"
212212
}
213213
egress_security_rules {
214214
description = "Path discovery"
@@ -270,8 +270,8 @@ resource oci_core_security_list endpoint {
270270
vcn_id = data.oci_core_vcn.vcn.id
271271
}
272272

273-
resource oci_core_default_security_list svcLB {
274-
display_name = "Service Load Balancer"
273+
resource "oci_core_default_security_list" "svcLB" {
274+
display_name = "Service Load Balancer"
275275
manage_default_resource_id = data.oci_core_vcn.vcn.default_security_list_id
276276
}
277277

infra/k8s/oke/terraform/main_var.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
variable "ociTenancyOcid" {}
55
variable "ociCompartmentOcid" {}
66
variable "ociRegionIdentifier" {}
7-
variable "vcnOcid" {}
7+
variable "vcnOcid" {}
8+
9+
variable "kubernetes_version" {
10+
description = "OKE Version"
11+
type = string
12+
default = "v1.27.2"
13+
}

infra/k8s/oke/terraform/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
//Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
provider "oci" {
5-
region = var.ociRegionIdentifier
5+
region = var.ociRegionIdentifier
66
}

0 commit comments

Comments
 (0)