33
44# Used to retrieve cluster CA certificate or configure local kube context
55
6- data "oci_containerengine_clusters" "cluster " {
7- count = local . cluster_enabled ? 1 : 0
6+ data "oci_containerengine_clusters" "existing_cluster " {
7+ count = var . cluster_id != null ? 1 : 0
88 compartment_id = local. compartment_id
99
1010 state = [" ACTIVE" ," UPDATING" ]
1111 filter {
1212 name = " id"
13- values = [local . cluster_id ]
13+ values = [var . cluster_id ]
1414 }
1515}
1616
1717data "oci_containerengine_cluster_kube_config" "public" {
18- count = local. cluster_enabled && length ( local. public_endpoint ) > 0 ? 1 : 0
18+ count = local. cluster_enabled && local. public_endpoint_available ? 1 : 0
1919
2020 cluster_id = local. cluster_id
2121 endpoint = " PUBLIC_ENDPOINT"
2222}
2323
2424data "oci_containerengine_cluster_kube_config" "private" {
25- count = local. cluster_enabled ? 1 : 0
25+ count = local. cluster_enabled && local . private_endpoint_available ? 1 : 0
2626
2727 cluster_id = local. cluster_id
2828 endpoint = " PRIVATE_ENDPOINT"
@@ -35,10 +35,11 @@ locals {
3535
3636 cluster-context = try (format (" context-%s" , substr (local. cluster_id , - 11 , - 1 )), " " )
3737
38- cluster_endpoints = one (flatten (data. oci_containerengine_clusters . cluster [* ]. clusters [* ]. endpoints ))
39- public_endpoint = local. cluster_endpoints != null ? lookup (local. cluster_endpoints , " public_endpoint" , " " ) : " "
40- kubeconfig_public = var. control_plane_is_public ? try (yamldecode (replace (lookup (one (data. oci_containerengine_cluster_kube_config . public ), " content" , " " ), local. cluster-context , var. cluster_name )), tomap ({})) : null
41- kubeconfig_private = try (yamldecode (replace (lookup (one (data. oci_containerengine_cluster_kube_config . private ), " content" , " " ), local. cluster-context , var. cluster_name )), tomap ({}))
38+ existing_cluster_endpoints = coalesce (one (flatten (data. oci_containerengine_clusters . existing_cluster [* ]. clusters [* ]. endpoints )), tomap ({}))
39+ public_endpoint_available = var. cluster_id != null ? length (lookup (local. existing_cluster_endpoints , " public_endpoint" , " " )) > 0 : var. control_plane_is_public && var. assign_public_ip_to_control_plane
40+ private_endpoint_available = var. cluster_id != null ? length (lookup (local. existing_cluster_endpoints , " private_endpoint" , " " )) > 0 : true
41+ kubeconfig_public = var. control_plane_is_public ? try (yamldecode (replace (lookup (one (data. oci_containerengine_cluster_kube_config . public ), " content" , " " ), local. cluster-context , var. cluster_name )), tomap ({})) : null
42+ kubeconfig_private = try (yamldecode (replace (lookup (one (data. oci_containerengine_cluster_kube_config . private ), " content" , " " ), local. cluster-context , var. cluster_name )), tomap ({}))
4243
4344 kubeconfig_clusters = try (lookup (local. kubeconfig_private , " clusters" , []), [])
4445 apiserver_private_host = (var. create_cluster
@@ -143,13 +144,13 @@ output "cluster_id" {
143144
144145output "cluster_endpoints" {
145146 description = " Endpoints for the OKE cluster"
146- value = var. create_cluster ? one (module. cluster [* ]. endpoints ) : null
147+ value = var. create_cluster ? one (module. cluster [* ]. endpoints ) : local . existing_cluster_endpoints
147148}
148149
149150output "cluster_kubeconfig" {
150151 description = " OKE kubeconfig"
151152 value = var. output_detail ? (
152- var . control_plane_is_public ? local. kubeconfig_public : local. kubeconfig_private
153+ local . public_endpoint_available ? local. kubeconfig_public : local. kubeconfig_private
153154 ) : null
154155}
155156
0 commit comments