Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export config from module #93

Merged
merged 4 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/controller_pool/assets/kubeconfig_copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
/usr/bin/ssh -i $ssh_private_key_path -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$controller "while true; do if ! type kubeadm > /dev/null; then sleep 20; else break; fi; done"
sleep 360
/usr/bin/scp -i $ssh_private_key_path -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -q root@$controller:/etc/kubernetes/admin.conf $local_path/kubeconfig;

25 changes: 25 additions & 0 deletions modules/controller_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ resource "metal_device" "k8s_controller_standby" {
project_id = var.project_id
}

resource "null_resource" "kubeconfig" {
provisioner "local-exec" {
environment = {
controller = metal_device.k8s_primary.network.0.address
kube_token = var.kube_token
ssh_private_key_path = var.ssh_private_key_path
local_path = path.root
}

command = "sh ${path.module}/assets/kubeconfig_copy.sh"
}

depends_on = [
null_resource.key_wait_transfer
]
}

data "local_file" "kubeconfig" {
filename = "${path.root}/kubeconfig"

depends_on = [
null_resource.kubeconfig
]
}

resource "null_resource" "key_wait_transfer" {
count = var.control_plane_node_count

Expand Down
5 changes: 5 additions & 0 deletions modules/controller_pool/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ output "controller_addresses" {
# description = "Control Plane Node Addresses"
# value = "\n${join("\n${metal_device.k8s_controller_standby.*.network.0.address}")}\n"
# }

output "kubeconfig" {
description = "Kubeconfig for the newly created cluster"
value = data.local_file.kubeconfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = data.local_file.kubeconfig
value = abspath(data.local_file.kubeconfig)

}
2 changes: 1 addition & 1 deletion modules/controller_pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ variable "loadbalancer_type" {
type = string
description = "The type of Load Balancer to configure with the Equinix CCM"
default = "metallb"
}
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ output "kubernetes_api_address" {
description = "The address of the Kubernetes API"
value = module.controllers.controller_addresses
}

output "kubernetes_kubeconfig" {
description = "Kubeconfig for the newly created cluster"
value = module.controllers.kubeconfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = module.controllers.kubeconfig
value = module.controllers.kubeconfig
sensitive = true

}