Skip to content

Commit 252a14b

Browse files
authored
Merge pull request #165 from junior/feature/use_existent_oke
Feature/use existent oke
2 parents 457ee44 + 20191b2 commit 252a14b

File tree

8 files changed

+111
-51
lines changed

8 files changed

+111
-51
lines changed

deploy/complete/terraform/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

deploy/complete/terraform/datasources.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ data "oci_identity_availability_domains" "ADs" {
1919

2020
# Gets kubeconfig
2121
data "oci_containerengine_cluster_kube_config" "oke_cluster_kube_config" {
22-
cluster_id = oci_containerengine_cluster.oke_mushop_cluster.id
22+
cluster_id = var.create_new_oke_cluster ? oci_containerengine_cluster.oke_mushop_cluster[0].id : var.existent_oke_cluster_id
2323
}
2424

2525

@@ -37,7 +37,7 @@ locals {
3737
## Kubernetes Service: mushop-utils-ingress-nginx-controller
3838
data "kubernetes_service" "mushop_ingress" {
3939
metadata {
40-
name = "mushop-utils-ingress-nginx-controller" # mushop-utils included to be backwards compatible to the docs and setup chart install
40+
name = "mushop-utils-ingress-nginx-controller" # mushop-utils name included to be backwards compatible to the docs and setup chart install
4141
namespace = kubernetes_namespace.mushop_utilities_namespace.id
4242
}
4343
depends_on = [helm_release.ingress-nginx]

deploy/complete/terraform/oke-network.tf

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,79 +7,91 @@ resource "oci_core_virtual_network" "oke_mushop_vcn" {
77
compartment_id = var.compartment_ocid
88
display_name = "OKE MuShop VCN - ${random_string.deploy_id.result}"
99
dns_label = "oke${random_string.deploy_id.result}"
10+
11+
count = var.create_new_oke_cluster ? 1 : 0
1012
}
1113

1214
resource "oci_core_subnet" "oke_mushop_subnet" {
1315
cidr_block = lookup(var.network_cidrs, "SUBNET-REGIONAL-CIDR")
1416
compartment_id = var.compartment_ocid
1517
display_name = "oke-mushop-subnet-${random_string.deploy_id.result}"
1618
dns_label = "okesubnet${random_string.deploy_id.result}"
17-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
19+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
1820
prohibit_public_ip_on_vnic = (var.cluster_visibility == "Private") ? true : false
19-
route_table_id = oci_core_route_table.oke_mushop_route_table.id
20-
dhcp_options_id = oci_core_virtual_network.oke_mushop_vcn.default_dhcp_options_id
21-
security_list_ids = [oci_core_security_list.oke_mushop_security_list.id]
21+
route_table_id = oci_core_route_table.oke_mushop_route_table[0].id
22+
dhcp_options_id = oci_core_virtual_network.oke_mushop_vcn[0].default_dhcp_options_id
23+
security_list_ids = [oci_core_security_list.oke_mushop_security_list[0].id]
24+
25+
count = var.create_new_oke_cluster ? 1 : 0
2226
}
2327

2428
resource "oci_core_subnet" "oke_mushop_lb_subnet" {
2529
cidr_block = lookup(var.network_cidrs, "LB-SUBNET-REGIONAL-CIDR")
2630
compartment_id = var.compartment_ocid
2731
display_name = "oke-mushop-lb-subnet-${random_string.deploy_id.result}"
2832
dns_label = "okelbsubnet${random_string.deploy_id.result}"
29-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
33+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
3034
prohibit_public_ip_on_vnic = false
31-
route_table_id = oci_core_route_table.oke_mushop_lb_route_table.id
32-
dhcp_options_id = oci_core_virtual_network.oke_mushop_vcn.default_dhcp_options_id
33-
security_list_ids = [oci_core_security_list.oke_mushop_lb_security_list.id]
35+
route_table_id = oci_core_route_table.oke_mushop_lb_route_table[0].id
36+
dhcp_options_id = oci_core_virtual_network.oke_mushop_vcn[0].default_dhcp_options_id
37+
security_list_ids = [oci_core_security_list.oke_mushop_lb_security_list[0].id]
38+
39+
count = var.create_new_oke_cluster ? 1 : 0
3440
}
3541

3642
resource "oci_core_route_table" "oke_mushop_route_table" {
3743
compartment_id = var.compartment_ocid
38-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
44+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
3945
display_name = "oke-mushop-route-table-${random_string.deploy_id.result}"
4046

4147
route_rules {
4248
destination = lookup(var.network_cidrs, "ALL-CIDR")
4349
destination_type = "CIDR_BLOCK"
44-
network_entity_id = (var.cluster_visibility == "Private") ? oci_core_nat_gateway.oke_mushop_nat_gateway[0].id : oci_core_internet_gateway.oke_mushop_internet_gateway.id
50+
network_entity_id = (var.cluster_visibility == "Private") ? oci_core_nat_gateway.oke_mushop_nat_gateway[0].id : oci_core_internet_gateway.oke_mushop_internet_gateway[0].id
4551
}
52+
53+
count = var.create_new_oke_cluster ? 1 : 0
4654
}
4755

4856
resource "oci_core_route_table" "oke_mushop_lb_route_table" {
4957
compartment_id = var.compartment_ocid
50-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
58+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
5159
display_name = "oke-mushop-lb-route-table-${random_string.deploy_id.result}"
5260

5361
route_rules {
5462
destination = lookup(var.network_cidrs, "ALL-CIDR")
5563
destination_type = "CIDR_BLOCK"
56-
network_entity_id = oci_core_internet_gateway.oke_mushop_internet_gateway.id
64+
network_entity_id = oci_core_internet_gateway.oke_mushop_internet_gateway[0].id
5765
}
66+
67+
count = var.create_new_oke_cluster ? 1 : 0
5868
}
5969

6070
resource "oci_core_nat_gateway" "oke_mushop_nat_gateway" {
6171
block_traffic = "false"
6272
compartment_id = var.compartment_ocid
6373
display_name = "oke-mushop-nat-gateway-${random_string.deploy_id.result}"
64-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
74+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
6575

66-
count = (var.cluster_visibility == "Private") ? 1 : 0
76+
count = var.create_new_oke_cluster ? ((var.cluster_visibility == "Private") ? 1 : 0) : 0
6777
}
6878

6979
resource "oci_core_internet_gateway" "oke_mushop_internet_gateway" {
7080
compartment_id = var.compartment_ocid
7181
display_name = "oke-mushop-internet-gateway-${random_string.deploy_id.result}"
7282
enabled = true
73-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
83+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
84+
85+
count = var.create_new_oke_cluster ? 1 : 0
7486
}
7587

7688
resource "oci_core_service_gateway" "oke_mushop_service_gateway" {
7789
compartment_id = var.compartment_ocid
7890
display_name = "oke-mushop-service-gateway-${random_string.deploy_id.result}"
79-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
91+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
8092
services {
8193
service_id = lookup(data.oci_core_services.all_services.services[0], "id")
8294
}
8395

84-
count = var.mushop_mock_mode_all ? 0 : 1
96+
count = var.create_new_oke_cluster ? (var.mushop_mock_mode_all ? 0 : 1) : 0
8597
}

deploy/complete/terraform/oke-securitylists.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
resource oci_core_security_list oke_mushop_security_list {
66
compartment_id = var.compartment_ocid
77
display_name = "oke-mushop-wkr-seclist-${random_string.deploy_id.result}"
8-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
8+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
99

1010
egress_security_rules {
1111
destination = lookup(var.network_cidrs, "SUBNET-REGIONAL-CIDR")
@@ -46,12 +46,13 @@ resource oci_core_security_list oke_mushop_security_list {
4646
}
4747
}
4848

49+
count = var.create_new_oke_cluster ? 1 : 0
4950
}
5051

5152
resource oci_core_security_list oke_mushop_lb_security_list {
5253
compartment_id = var.compartment_ocid
5354
display_name = "oke-mushop-wkr-lb-seclist-${random_string.deploy_id.result}"
54-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
55+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
5556

5657
egress_security_rules {
5758
destination = lookup(var.network_cidrs, "ALL-CIDR")
@@ -66,4 +67,6 @@ resource oci_core_security_list oke_mushop_lb_security_list {
6667
protocol = "6"
6768
stateless = true
6869
}
70+
71+
count = var.create_new_oke_cluster ? 1 : 0
6972
}

deploy/complete/terraform/oke.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ resource "oci_containerengine_cluster" "oke_mushop_cluster" {
66
compartment_id = var.compartment_ocid
77
kubernetes_version = var.k8s_version
88
name = "${var.cluster_name}-${random_string.deploy_id.result}"
9-
vcn_id = oci_core_virtual_network.oke_mushop_vcn.id
9+
vcn_id = oci_core_virtual_network.oke_mushop_vcn[0].id
1010

1111
options {
12-
service_lb_subnet_ids = [oci_core_subnet.oke_mushop_lb_subnet.id]
12+
service_lb_subnet_ids = [oci_core_subnet.oke_mushop_lb_subnet[0].id]
1313
add_ons {
1414
is_kubernetes_dashboard_enabled = var.cluster_options_add_ons_is_kubernetes_dashboard_enabled
1515
is_tiller_enabled = false # Default is false, left here for reference
@@ -18,10 +18,12 @@ resource "oci_containerengine_cluster" "oke_mushop_cluster" {
1818
is_pod_security_policy_enabled = var.cluster_options_admission_controller_options_is_pod_security_policy_enabled
1919
}
2020
}
21+
22+
count = var.create_new_oke_cluster ? 1 : 0
2123
}
2224

2325
resource "oci_containerengine_node_pool" "oke_mushop_node_pool" {
24-
cluster_id = oci_containerengine_cluster.oke_mushop_cluster.id
26+
cluster_id = oci_containerengine_cluster.oke_mushop_cluster[0].id
2527
compartment_id = var.compartment_ocid
2628
kubernetes_version = var.k8s_version
2729
name = var.node_pool_name
@@ -34,7 +36,7 @@ resource "oci_containerengine_node_pool" "oke_mushop_node_pool" {
3436

3537
content {
3638
availability_domain = placement_configs.value.name
37-
subnet_id = oci_core_subnet.oke_mushop_subnet.id
39+
subnet_id = oci_core_subnet.oke_mushop_subnet[0].id
3840
}
3941
}
4042
size = var.num_pool_workers
@@ -50,6 +52,8 @@ resource "oci_containerengine_node_pool" "oke_mushop_node_pool" {
5052
key = "name"
5153
value = var.node_pool_name
5254
}
55+
56+
count = var.create_new_oke_cluster ? 1 : 0
5357
}
5458

5559
# Local kubeconfig for when using Terraform locally. Not used by Oracle Resource Manager

deploy/complete/terraform/schema.yaml

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@ variableGroups:
2020
- tenancy_ocid
2121
- region
2222
visible: false
23-
- title: "General Configuration"
23+
- title: "OKE General Configuration"
2424
variables:
25+
- create_new_oke_cluster
26+
- existent_oke_cluster_id
2527
- cluster_name
2628
- k8s_version
2729
- cluster_visibility
2830
visible: true
29-
- title: "Worker Nodes"
31+
- title: "OKE Worker Nodes"
3032
variables:
3133
- node_pool_shape
3234
- num_pool_workers
3335
- node_pool_name
34-
visible: true
36+
visible: #($create_new_oke_cluster = true)
37+
and:
38+
- create_new_oke_cluster
3539
- title: "Add Ons"
3640
variables:
3741
- cluster_options_add_ons_is_kubernetes_dashboard_enabled
@@ -99,11 +103,28 @@ variables:
99103
description: "The compartment in which to create compute instance(s)"
100104
required: true
101105

106+
create_new_oke_cluster:
107+
type: boolean
108+
title: "Create new OKE Cluster"
109+
description: "Creates a new OKE cluster, node pool and network resources"
110+
111+
existent_oke_cluster_id:
112+
type: string
113+
title: "OKE Cluster id"
114+
description: "Cluster Id of the existent OKE"
115+
required: true
116+
visible: #($create_new_oke_cluster = false)
117+
not:
118+
- create_new_oke_cluster
119+
102120
cluster_name:
103121
type: string
104122
title: "Cluster Name Prefix"
105123
description: "OKE cluster name prefix"
106124
required: true
125+
visible: #($create_new_oke_cluster = true)
126+
and:
127+
- create_new_oke_cluster
107128

108129
k8s_version:
109130
type: enum
@@ -113,6 +134,9 @@ variables:
113134
title: "Kubernetes Version"
114135
description: "Kubernetes version installed on your master and worker nodes"
115136
required: true
137+
visible: #($create_new_oke_cluster = true)
138+
and:
139+
- create_new_oke_cluster
116140

117141
cluster_visibility:
118142
type: enum
@@ -122,6 +146,9 @@ variables:
122146
title: "Choose visibility type"
123147
description: "The Kubernetes worker nodes that are created will be hosted in public or private subnet(s)"
124148
required: true
149+
visible: #($create_new_oke_cluster = true)
150+
and:
151+
- create_new_oke_cluster
125152

126153
node_pool_shape:
127154
type: oci:core:instanceshape:name
@@ -140,18 +167,21 @@ variables:
140167
required: true
141168

142169
node_pool_name:
143-
visible: #($show_advanced == ""Yes"")
144-
eq:
145-
- show_advanced
146-
- "Yes"
147170
type: string
148171
title: "Node Pool Name"
149172
description: "Name of the node pool"
150173
required: true
174+
visible: #($show_advanced == ""Yes"")
175+
eq:
176+
- show_advanced
177+
- "Yes"
151178

152179
cluster_options_add_ons_is_kubernetes_dashboard_enabled:
153180
type: boolean
154181
title: "Kubernetes Dashboard Enabled"
182+
visible: #($create_new_oke_cluster = true)
183+
and:
184+
- create_new_oke_cluster
155185

156186
# Advanced Options
157187
show_advanced:
@@ -164,48 +194,48 @@ variables:
164194
required: true
165195

166196
generate_public_ssh_key:
197+
type: boolean
198+
title: "Auto generate public ssh key?"
199+
required: true
167200
visible: #($show_advanced == ""Yes"")
168201
eq:
169202
- show_advanced
170203
- "Yes"
171-
type: boolean
172-
title: "Auto generate public ssh key?"
173-
required: true
174204

175205
public_ssh_key:
206+
type: string
207+
title: "Input SSH public key"
208+
description: "In order to access your private nodes with a public SSH key you will need to set up a bastion host (a.k.a. jump box). If using public nodes, bastion is not needed. Left blank to not import keys."
209+
required: false
176210
visible: #($show_advanced == ""Yes"") + ($generate_public_ssh_key == "false")
177211
and:
178212
- eq:
179213
- show_advanced
180214
- "Yes"
181215
- not:
182216
- generate_public_ssh_key
183-
type: string
184-
title: "Input SSH public key"
185-
description: "In order to access your private nodes with a public SSH key you will need to set up a bastion host (a.k.a. jump box). If using public nodes, bastion is not needed. Left blank to not import keys."
186-
required: false
187217

188218
image_operating_system:
189-
visible: #($show_advanced == ""Yes"")
190-
eq:
191-
- show_advanced
192-
- "Yes"
193219
type: enum
194220
title: "Image OS"
195221
description: "The OS/image installed on all nodes in the node pool."
196222
enum:
197223
- "Oracle Linux"
198224
required: true
199-
200-
image_operating_system_version:
201225
visible: #($show_advanced == ""Yes"")
202226
eq:
203227
- show_advanced
204228
- "Yes"
229+
230+
image_operating_system_version:
205231
type: string
206232
required: true
207233
title: "Image OS Version"
208-
description: "The OS/image version installed on all nodes in the node pool."
234+
description: "The OS/image version installed on all nodes in the node pool."
235+
visible: #($show_advanced == ""Yes"")
236+
eq:
237+
- show_advanced
238+
- "Yes"
209239

210240
mushop_mock_mode_all:
211241
visible: yes

deploy/complete/terraform/terraform.tfvars.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ user_ocid = "" # e.g.: "ocid1.user..." or leave blank if using CloudShell
1212
# region
1313
region = "us-ashburn-1"
1414

15-
# cluster_visibility
15+
# OKE Cluster
16+
## cluster_visibility
1617
cluster_visibility = "Private"
18+
## create_new_oke_cluster
19+
create_new_oke_cluster = true
20+
existent_oke_cluster_id = "" # e.g.: ocid1.cluster.oc1.i...
1721

1822
# public_ssh_key
1923
generate_public_ssh_key = true # if true, auto generate public and private keys and assign to the node pool.
2024
public_ssh_key = "" # if generate_public_ssh_key=true, public_ssh_key is ignored. if generate_public_ssh_key=false, assign public_ssh_key, that can be nothing if ""
2125

2226
# MuShop
27+
## Enable Mock Mode
2328
mushop_mock_mode_all = false # Set to true if do not want to provision ATP, ObjectStorage and mock all services

0 commit comments

Comments
 (0)