diff --git a/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig-extraction.tf b/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig-extraction.tf index 4e381a8..0749c32 100644 --- a/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig-extraction.tf +++ b/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig-extraction.tf @@ -17,23 +17,11 @@ EOT } } -data "local_file" "kube_config_raw_file" { +data "local_file" "kubeconfig_file" { filename = local.kubeconfig_file depends_on = [ null_resource.copy_kubeconfig ] } - -# output "kube_config_raw" { -# value = data.local_file.kube_config_raw_file -# description = "Kubeconfig for this cluster" -# } - -# data "external" "extract_kubeconfig_file" { -# program = ["bash", "${path.module}/kubeconfig_extraction.sh"] - -# query = { -# PATH_ROOT=path.root -# SERVER_IP=openstack_compute_instance_v2.kubernetes_server.access_ip_v4 -# SSH_KEY=local.ssh_keys.private_key_file -# # KUBECONFIG_FILE=local.kubeconfig_file -# } -# } \ No newline at end of file +output "kubeconfig_raw" { + value = data.local_file.kubeconfig_file.content + description = "Kubeconfig for this cluster" +} diff --git a/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig_extraction.sh b/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig_extraction.sh deleted file mode 100644 index ab95380..0000000 --- a/deployment/terraform/modules/openstack-kubernetes-infra/kubeconfig_extraction.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# ============================== -# Variables (from Terraform) -# ============================== -PATH_ROOT=${path.root} -SERVER_IP=${openstack_compute_instance_v2.kubernetes_server.access_ip_v4} -SSH_KEY=${local.ssh_keys.private_key_file} -KUBECONFIG_FILE=${local.kubeconfig_file} - -# ============================== -# Script Logic -# ============================== - -# Create .build directory if it doesn't exist -mkdir -p "${PATH_ROOT}/.build/" - -# Add server's SSH key to a custom known_hosts file -ssh-keyscan -H "${SERVER_IP}" >> "${PATH_ROOT}/.build/.known_hosts_cogstack" - -# Securely copy the K3s kubeconfig file from the server -scp \ - -o UserKnownHostsFile="${PATH_ROOT}/.build/.known_hosts_cogstack" \ - -o StrictHostKeyChecking=yes \ - -i "${SSH_KEY}" \ - "ubuntu@${SERVER_IP}:/etc/rancher/k3s/k3s.yaml" \ - "${KUBECONFIG_FILE}" - -# Replace localhost with the actual server IP in the kubeconfig -sed -i "s/127\.0\.0\.1/${SERVER_IP}/" "${KUBECONFIG_FILE}" - -echo "Kubeconfig successfully fetched and updated at: ${KUBECONFIG_FILE}" \ No newline at end of file diff --git a/deployment/terraform/modules/openstack-kubernetes-infra/outputs.tf b/deployment/terraform/modules/openstack-kubernetes-infra/outputs.tf index 2ad485e..6289ed1 100644 --- a/deployment/terraform/modules/openstack-kubernetes-infra/outputs.tf +++ b/deployment/terraform/modules/openstack-kubernetes-infra/outputs.tf @@ -6,7 +6,7 @@ output "created_hosts" { name = k } }, { - (local.controller_host.name) : local.controller_host_instance + (local.controller_host.name) : local.controller_host_instance }) description = "Created Hosts: A map of { hostname: { data } }" diff --git a/deployment/terraform/modules/openstack-kubernetes-infra/shared-locals.tf b/deployment/terraform/modules/openstack-kubernetes-infra/shared-locals.tf index f510522..e2d95c2 100644 --- a/deployment/terraform/modules/openstack-kubernetes-infra/shared-locals.tf +++ b/deployment/terraform/modules/openstack-kubernetes-infra/shared-locals.tf @@ -5,7 +5,7 @@ locals { locals { - controller_host = one([for host in var.host_instances : host if host.is_controller]) + controller_host = one([for host in var.host_instances : host if host.is_controller]) created_controller_host = openstack_compute_instance_v2.kubernetes_server controller_host_instance = { name = local.controller_host.name @@ -16,7 +16,7 @@ locals { locals { output_file_directory = var.output_file_directory != null ? var.output_file_directory : "${path.root}/.build" - kubeconfig_file = "${local.output_file_directory}/downloaded-kubeconfig.yaml" + kubeconfig_file = "${local.output_file_directory}/downloaded-kubeconfig.yaml" } resource "random_id" "server" { diff --git a/deployment/terraform/modules/openstack-kubernetes-infra/variables.tf b/deployment/terraform/modules/openstack-kubernetes-infra/variables.tf index 556a44b..302746a 100644 --- a/deployment/terraform/modules/openstack-kubernetes-infra/variables.tf +++ b/deployment/terraform/modules/openstack-kubernetes-infra/variables.tf @@ -57,7 +57,7 @@ variable "ssh_key_pair" { } variable "output_file_directory" { - type = string - default = null + type = string + default = null description = "Optional path to write output files to. If directory doesnt exist it will be created" } \ No newline at end of file