Skip to content

Commit e6a7b69

Browse files
Terraform Team Automationvsin12
authored andcommitted
Added - Support for Enhanced Cluster/Serverless/Cluster AddOns
1 parent 8285f9b commit e6a7b69

33 files changed

+5123
-112
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "cluster_id" {
8+
9+
}
10+
11+
variable "kubernetes_version" {
12+
13+
}
14+
15+
variable "compartment_ocid" {
16+
}
17+
18+
variable "image_id" {
19+
20+
}
21+
22+
data "oci_containerengine_addon_options" "all" {
23+
#Required
24+
kubernetes_version = var.kubernetes_version
25+
}
26+
27+
data "oci_containerengine_addon_options" "name_filter_example" {
28+
#Required
29+
kubernetes_version = var.kubernetes_version
30+
#Optional, a name uniquely identifies an add-on, see all supported add-on names in data.oci_containerengine_addon_options.all.addon_options
31+
addon_name = "KubernetesDashboard"
32+
}
33+
34+
resource "oci_containerengine_addon" "addon_resource_example" {
35+
#Required, a name uniquely identifies an add-on, see all supported add-on names in data.oci_containerengine_addon_options.all.addon_options
36+
addon_name = "KubernetesDashboard"
37+
#Required
38+
cluster_id = var.cluster_id
39+
#Required, false values keeps installed resources of the addon on deletion. Set to true to fully remove resources
40+
remove_addon_resources_on_delete = true
41+
42+
/*
43+
configurations that are supported by the add-on specified by the addon_name, see all supported configurations in in data.oci_containerengine_addon_options.all.addon_options.
44+
Unless required by a specific add-on, most of add-ons only have optional configurations that allow customization.
45+
*/
46+
configurations {
47+
48+
}
49+
/*
50+
Optional, see all supported version in in data.oci_containerengine_addon_options.all.addon_options.
51+
It is highly recommended to not set this field to let service choose and manage addon version.
52+
*/
53+
version = "v1.0.0"
54+
}
55+
56+
data "oci_containerengine_addons" "addon_addon_data_source_list_example" {
57+
#Required
58+
cluster_id = var.cluster_id
59+
}
60+
61+
data "oci_containerengine_addon" "addon_data_source_singular_example" {
62+
#Required
63+
cluster_id = var.cluster_id
64+
#Required, a name uniquely identifies an add-on, see all supported add-on names in data.oci_containerengine_addon_options.all.addon_options
65+
addon_name = "KubernetesDashboard"
66+
}
67+
68+
/*
69+
A complete example to setup a cluster, then configure add-ons, then create node pool.
70+
*/
71+
data "oci_identity_availability_domain" "ad1" {
72+
compartment_id = var.tenancy_ocid
73+
ad_number = 1
74+
}
75+
76+
resource "oci_core_vcn" "test_vcn" {
77+
cidr_block = "10.0.0.0/16"
78+
compartment_id = var.compartment_ocid
79+
display_name = "tfVcnForClusters"
80+
}
81+
82+
resource "oci_core_internet_gateway" "test_ig" {
83+
compartment_id = var.compartment_ocid
84+
display_name = "tfClusterInternetGateway"
85+
vcn_id = oci_core_vcn.test_vcn.id
86+
}
87+
88+
resource "oci_core_route_table" "test_route_table" {
89+
compartment_id = var.compartment_ocid
90+
vcn_id = oci_core_vcn.test_vcn.id
91+
display_name = "tfClustersRouteTable"
92+
93+
route_rules {
94+
destination = "0.0.0.0/0"
95+
destination_type = "CIDR_BLOCK"
96+
network_entity_id = oci_core_internet_gateway.test_ig.id
97+
}
98+
}
99+
100+
resource "oci_core_subnet" "nodePool_Subnet_1" {
101+
#Required
102+
availability_domain = data.oci_identity_availability_domain.ad1.name
103+
cidr_block = "10.0.22.0/24"
104+
compartment_id = var.compartment_ocid
105+
vcn_id = oci_core_vcn.test_vcn.id
106+
107+
# Provider code tries to maintain compatibility with old versions.
108+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
109+
display_name = "tfSubNet1ForNodePool"
110+
route_table_id = oci_core_route_table.test_route_table.id
111+
}
112+
113+
resource "oci_containerengine_cluster" "test_cluster" {
114+
#Required
115+
compartment_id = var.compartment_ocid
116+
kubernetes_version = var.kubernetes_version
117+
name = "tfTestCluster"
118+
vcn_id = oci_core_vcn.test_vcn.id
119+
type = "ENHANCED_CLUSTER"
120+
}
121+
122+
resource "oci_containerengine_addon" "dashboard" {
123+
#Required, a name uniquely identifies an add-on, see all supported add-on names in data.oci_containerengine_addon_options.all.addon_options
124+
addon_name = "KubernetesDashboard"
125+
#Required
126+
cluster_id = oci_containerengine_cluster.test_cluster.id
127+
#Required, remove the resource on addon deletion
128+
remove_addon_resources_on_delete = true
129+
}
130+
131+
resource "oci_containerengine_node_pool" "test_node_pool" {
132+
#Required
133+
cluster_id = oci_containerengine_cluster.test_cluster.id
134+
compartment_id = var.compartment_ocid
135+
kubernetes_version = var.kubernetes_version
136+
name = "tfPool"
137+
node_shape = "VM.Standard2.1"
138+
139+
node_config_details {
140+
size = 1
141+
placement_configs {
142+
availability_domain = data.oci_identity_availability_domain.ad1.name
143+
subnet_id = oci_core_subnet.nodePool_Subnet_1.id
144+
}
145+
}
146+
147+
node_source_details {
148+
#Required
149+
image_id = var.image_id
150+
source_type = "IMAGE"
151+
152+
#Optional
153+
boot_volume_size_in_gbs = "60"
154+
}
155+
156+
//use terraform depends_on to enforce cluster->add-on->node pool DAG
157+
depends_on = [oci_containerengine_addon.dashboard]
158+
}

examples/container_engine/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ resource "oci_core_subnet" "nodePool_Subnet_2" {
155155
resource "oci_containerengine_cluster" "test_cluster" {
156156
#Required
157157
compartment_id = var.compartment_ocid
158-
kubernetes_version = data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions[0]
158+
kubernetes_version = reverse(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)[0]
159159
name = "tfTestCluster"
160160
vcn_id = oci_core_vcn.test_vcn.id
161161

@@ -180,7 +180,7 @@ resource "oci_containerengine_cluster" "test_cluster" {
180180

181181
admission_controller_options {
182182
#Optional
183-
is_pod_security_policy_enabled = true
183+
is_pod_security_policy_enabled = false
184184
}
185185

186186
kubernetes_network_config {
@@ -195,10 +195,10 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
195195
#Required
196196
cluster_id = oci_containerengine_cluster.test_cluster.id
197197
compartment_id = var.compartment_ocid
198-
kubernetes_version = data.oci_containerengine_node_pool_option.test_node_pool_option.kubernetes_versions[0]
198+
kubernetes_version = reverse(data.oci_containerengine_node_pool_option.test_node_pool_option.kubernetes_versions)[0]
199199
name = "tfPool"
200200
node_shape = "VM.Standard2.1"
201-
subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id, oci_core_subnet.nodePool_Subnet_2.id]
201+
subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id]
202202

203203
#Optional
204204
initial_node_labels {
@@ -222,18 +222,18 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
222222
boot_volume_size_in_gbs = "60"
223223
}
224224

225-
quantity_per_subnet = 2
225+
quantity_per_subnet = 1
226226
ssh_public_key = var.node_pool_ssh_public_key
227227
}
228228

229229
resource "oci_containerengine_node_pool" "test_flex_shape_node_pool" {
230230
#Required
231231
cluster_id = oci_containerengine_cluster.test_cluster.id
232232
compartment_id = var.compartment_ocid
233-
kubernetes_version = data.oci_containerengine_node_pool_option.test_node_pool_option.kubernetes_versions[0]
233+
kubernetes_version = reverse(data.oci_containerengine_node_pool_option.test_node_pool_option.kubernetes_versions)[0]
234234
name = "flexShapePool"
235235
node_shape = "VM.Standard.E3.Flex"
236-
subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id, oci_core_subnet.nodePool_Subnet_2.id]
236+
subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id]
237237

238238
node_source_details {
239239
#Required
@@ -246,7 +246,7 @@ resource "oci_containerengine_node_pool" "test_flex_shape_node_pool" {
246246
memory_in_gbs = 40
247247
}
248248

249-
quantity_per_subnet = 2
249+
quantity_per_subnet = 1
250250
ssh_public_key = var.node_pool_ssh_public_key
251251
}
252252

0 commit comments

Comments
 (0)