Skip to content

Commit

Permalink
Improve logic for kube_config datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
robo-cap authored and hyder committed Mar 28, 2024
1 parent 459d237 commit df62b3d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion module-cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

# Used to retrieve cluster CA certificate or configure local kube context

data "oci_containerengine_clusters" "cluster" {
count = local.cluster_enabled ? 1 : 0
compartment_id = local.compartment_id

state = ["ACTIVE","UPDATING"]
filter {
name = "id"
values = [local.cluster_id]
}
}

data "oci_containerengine_cluster_kube_config" "public" {
count = local.cluster_enabled && var.control_plane_is_public ? 1 : 0
count = local.cluster_enabled && length(local.public_endpoint) > 0 ? 1 : 0

cluster_id = local.cluster_id
endpoint = "PUBLIC_ENDPOINT"
}

data "oci_containerengine_cluster_kube_config" "private" {
count = local.cluster_enabled ? 1 : 0

cluster_id = local.cluster_id
endpoint = "PRIVATE_ENDPOINT"
}
Expand All @@ -21,6 +35,8 @@ locals {

cluster-context = try(format("context-%s", substr(local.cluster_id, -11, -1)), "")

cluster_endpoints = one(flatten(data.oci_containerengine_clusters.cluster[*].clusters[*].endpoints))
public_endpoint = local.cluster_endpoints != null ? lookup(local.cluster_endpoints, "public_endpoint", "") : ""
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
kubeconfig_private = try(yamldecode(replace(lookup(one(data.oci_containerengine_cluster_kube_config.private), "content", ""), local.cluster-context, var.cluster_name)), tomap({}))

Expand Down

0 comments on commit df62b3d

Please sign in to comment.