File tree Expand file tree Collapse file tree 2 files changed +52
-8
lines changed
deployment/terraform/modules/openstack-kubernetes-infra Expand file tree Collapse file tree 2 files changed +52
-8
lines changed Original file line number Diff line number Diff line change 1717 }
1818}
1919
20- data "local_file" "kube_config_raw_file" {
21- filename = local. kubeconfig_file
22- depends_on = [ null_resource. copy_kubeconfig ]
23- }
20+ # data "local_file" "kube_config_raw_file" {
21+ # filename = local.kubeconfig_file
22+ # depends_on = [ null_resource.copy_kubeconfig ]
23+ # }
24+
25+ # output "kube_config_raw" {
26+ # value = data.local_file.kube_config_raw_file
27+ # description = "Kubeconfig for this cluster"
28+ # }
29+
30+ # data "external" "extract_kubeconfig_file" {
31+ # program = ["bash", "${path.module}/kubeconfig_extraction.sh"]
2432
25- output "kube_config_raw" {
26- value = data. local_file . kube_config_raw_file
27- description = " Kubeconfig for this clustr"
28- }
33+ # query = {
34+ # PATH_ROOT=path.root
35+ # SERVER_IP=openstack_compute_instance_v2.kubernetes_server.access_ip_v4
36+ # SSH_KEY=local.ssh_keys.private_key_file
37+ # # KUBECONFIG_FILE=local.kubeconfig_file
38+ # }
39+ # }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # ==============================
5+ # Variables (from Terraform)
6+ # ==============================
7+ PATH_ROOT=${path.root}
8+ SERVER_IP=${openstack_compute_instance_v2.kubernetes_server.access_ip_v4}
9+ SSH_KEY=${local.ssh_keys.private_key_file}
10+ KUBECONFIG_FILE=${local.kubeconfig_file}
11+
12+ # ==============================
13+ # Script Logic
14+ # ==============================
15+
16+ # Create .build directory if it doesn't exist
17+ mkdir -p " ${PATH_ROOT} /.build/"
18+
19+ # Add server's SSH key to a custom known_hosts file
20+ ssh-keyscan -H " ${SERVER_IP} " >> " ${PATH_ROOT} /.build/.known_hosts_cogstack"
21+
22+ # Securely copy the K3s kubeconfig file from the server
23+ scp \
24+ -o UserKnownHostsFile=" ${PATH_ROOT} /.build/.known_hosts_cogstack" \
25+ -o StrictHostKeyChecking=yes \
26+ -i " ${SSH_KEY} " \
27+ " ubuntu@${SERVER_IP} :/etc/rancher/k3s/k3s.yaml" \
28+ " ${KUBECONFIG_FILE} "
29+
30+ # Replace localhost with the actual server IP in the kubeconfig
31+ sed -i " s/127\.0\.0\.1/${SERVER_IP} /" " ${KUBECONFIG_FILE} "
32+
33+ echo " Kubeconfig successfully fetched and updated at: ${KUBECONFIG_FILE} "
You can’t perform that action at this time.
0 commit comments