11//  Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
22//  Licensed under the Mozilla Public License v2.0
3- 
4- variable  "tenancy_ocid"  {
3+ variable  "user_ocid"  {
54}
65
7- variable  "cluster_id"  {
8- 
6+ variable  "fingerprint"  {
97}
108
11- variable  "kubernetes_version"  {
12- 
9+ variable  "private_key_path"  {
1310}
1411
15- variable  "compartment_ocid"  {
12+ variable  "region"  {
13+   default  =  " us-ashburn-1" 
1614}
1715
18- variable  "image_id"  {
1916
17+ variable  "tenancy_ocid"  {
2018}
2119
22- data  "oci_containerengine_addon_options"  "all"  {
23-     # Required
24-     kubernetes_version  =   var. kubernetes_version 
25- }
20+ variable  "cluster_id"  {
2621
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" 
3222}
3323
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  {
24+ variable  "kubernetes_version"  {
4725
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" 
5426}
5527
56- data  "oci_containerengine_addons"  "addon_addon_data_source_list_example"  {
57-     # Required
58-     cluster_id  =   var. cluster_id 
28+ variable  "compartment_ocid"  {
5929}
6030
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" 
31+ provider  "oci"  {
32+   region            =   var. region 
33+   tenancy_ocid      =   var. tenancy_ocid 
34+   user_ocid         =   var. user_ocid 
35+   fingerprint       =   var. fingerprint 
36+   private_key_path  =   var. private_key_path 
6637}
6738
6839/* 
@@ -113,7 +84,7 @@ resource "oci_core_subnet" "nodePool_Subnet_1" {
11384resource  "oci_containerengine_cluster"  "test_cluster"  {
11485    # Required
11586    compartment_id      =   var. compartment_ocid 
116-     kubernetes_version  =  var . kubernetes_version 
87+     kubernetes_version  =  reverse (data . oci_containerengine_cluster_option . test_cluster_option . kubernetes_versions )[ 0 ] 
11788    name                =  " tfTestCluster" 
11889    vcn_id              =   oci_core_vcn. test_vcn . id 
11990    type                =  " ENHANCED_CLUSTER" 
@@ -126,13 +97,21 @@ resource "oci_containerengine_addon" "dashboard" {
12697    cluster_id  =   oci_containerengine_cluster. test_cluster . id 
12798    # Required, remove the resource on addon deletion
12899    remove_addon_resources_on_delete  =  true 
100+     dynamic  configurations  {
101+         for_each  =   local. addon_mappings 
102+ 
103+         content  {
104+             key  =  configurations. value . key 
105+             value  =   configurations. value . value 
106+             }
107+         }
129108}
130109
131110resource  "oci_containerengine_node_pool"  "test_node_pool"  {
132111    # Required
133112    cluster_id          =   oci_containerengine_cluster. test_cluster . id 
134113    compartment_id      =   var. compartment_ocid 
135-     kubernetes_version  =  var . kubernetes_version 
114+     kubernetes_version  =  reverse (data . oci_containerengine_cluster_option . test_cluster_option . kubernetes_versions )[ 0 ] 
136115    name                =  " tfPool" 
137116    node_shape          =  " VM.Standard2.1" 
138117
@@ -146,7 +125,7 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
146125
147126    node_source_details  {
148127        # Required
149-         image_id     =  var . image_id 
128+         image_id     =  local . image_id 
150129        source_type  =  " IMAGE" 
151130
152131        # Optional
@@ -155,4 +134,40 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
155134
156135    // use terraform depends_on to enforce cluster->add-on->node pool DAG
157136    depends_on  =   [oci_containerengine_addon . dashboard ]
137+ }
138+ 
139+ data  "oci_containerengine_cluster_option"  "test_cluster_option"  {
140+   cluster_option_id  =  " all" 
141+ }
142+ 
143+ data  "oci_containerengine_node_pool_option"  "test_node_pool_option"  {
144+   node_pool_option_id  =  " all" 
145+ }
146+ 
147+ data  "oci_core_images"  "shape_specific_images"  {
148+   # Required
149+   compartment_id  =   var. tenancy_ocid 
150+   shape  =  " VM.Standard2.1" 
151+ }
152+ 
153+ locals  {
154+   all_images  =  " ${ data . oci_core_images . shape_specific_images . images } " 
155+   all_sources  =  " ${ data . oci_containerengine_node_pool_option . test_node_pool_option . sources } " 
156+ 
157+   compartment_images  =   [for  image  in  local . all_images  :  image . id  if  length (regexall (" Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*"  ,image. display_name )) >  0  ]
158+ 
159+   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 ]
160+ 
161+   image_id  =  tolist (setintersection ( toset (local. compartment_images ), toset (local. oracle_linux_images )))[0 ]
162+ 
163+   addon_mappings  =   {
164+         mapping1 =  {
165+             key =  " numOfReplicas" 
166+             value =  " 1" 
167+         }
168+         mapping2 =  {
169+             key =  " nodeSelectors" 
170+             value =  " {\" pool\" :\" system\" }" 
171+         }
172+   }
158173}
0 commit comments