diff --git a/agents.tf b/agents.tf index 46a57c0..f83962f 100644 --- a/agents.tf +++ b/agents.tf @@ -31,6 +31,12 @@ resource "hcloud_server" "agents" { destination = "/root/config.ign" } + # Combustion script file to install k3s-selinux + provisioner "file" { + content = local.combustion_script + destination = "/root/script" + } + # Install MicroOS provisioner "remote-exec" { inline = local.microOS_install_commands @@ -69,20 +75,6 @@ resource "hcloud_server" "agents" { inline = local.install_k3s_agent } - # Issue a reboot command and wait for the node to reboot - provisioner "local-exec" { - command = "ssh ${local.ssh_args} root@${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3" - } - provisioner "local-exec" { - command = <<-EOT - until ssh ${local.ssh_args} -o ConnectTimeout=2 root@${self.ipv4_address} true 2> /dev/null - do - echo "Waiting for MicroOS to reboot and become available..." - sleep 2 - done - EOT - } - # Upon reboot verify that k3s agent starts correctly provisioner "remote-exec" { inline = [ @@ -97,7 +89,6 @@ resource "hcloud_server" "agents" { ] } - network { network_id = hcloud_network.k3s.id ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 513 + count.index) diff --git a/locals.tf b/locals.tf index 6afe266..6c5a399 100644 --- a/locals.tf +++ b/locals.tf @@ -20,6 +20,7 @@ locals { microOS_install_commands = [ "set -ex", + "apt-get update", "apt-get install -y aria2", "aria2c --follow-metalink=mem https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-kvm-and-xen.qcow2.meta4", "qemu-img convert -p -f qcow2 -O host_device $(ls -a | grep -ie '^opensuse.*microos.*qcow2$') /dev/sda", @@ -32,9 +33,20 @@ locals { "mount /dev/sda5 /mnt", "mkdir /mnt/ignition", "cp /root/config.ign /mnt/ignition/config.ign", + "mkdir /mnt/combustion", + "cp /root/script /mnt/combustion/script", "umount /mnt" ] + combustion_script = < /dev/null - do - echo "Waiting for MicroOS to reboot and become available..." - sleep 2 - done - EOT - } - # Upon reboot verify that the k3s server is starts, and wait for k3s to be ready to receive commands provisioner "remote-exec" { inline = [ + "systemctl start k3s", # prepare the post_install directory "mkdir -p /tmp/post_install", # wait for k3s to become ready diff --git a/output.tf b/output.tf index 310a0dd..330d587 100644 --- a/output.tf +++ b/output.tf @@ -8,10 +8,12 @@ output "agents_public_ip" { description = "The public IP addresses of the agent server." } +/* output "load_balancer_public_ip" { description = "The public IPv4 address of the Hetzner load balancer" value = data.hcloud_load_balancer.traefik.ipv4 } +*/ output "kubeconfig_file" { value = local.kubeconfig_external diff --git a/servers.tf b/servers.tf index 0db1ea5..7e918d9 100644 --- a/servers.tf +++ b/servers.tf @@ -30,6 +30,12 @@ resource "hcloud_server" "control_planes" { destination = "/root/config.ign" } + # Combustion script file to install k3s-selinux + provisioner "file" { + content = local.combustion_script + destination = "/root/script" + } + # Install MicroOS provisioner "remote-exec" { inline = local.microOS_install_commands @@ -74,23 +80,10 @@ resource "hcloud_server" "control_planes" { inline = local.install_k3s_server } - # Issue a reboot command and wait for the node to reboot - provisioner "local-exec" { - command = "ssh ${local.ssh_args} root@${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3" - } - provisioner "local-exec" { - command = <<-EOT - until ssh ${local.ssh_args} -o ConnectTimeout=2 root@${self.ipv4_address} true 2> /dev/null - do - echo "Waiting for MicroOS to reboot and become available..." - sleep 2 - done - EOT - } - # Upon reboot verify that the k3s server starts correctly provisioner "remote-exec" { inline = [ + "systemctl start k3s", <<-EOT timeout 120 bash < /dev/null; do