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+ }
0 commit comments