From 8723b27d099f494a8679d369ed8405bc92c30a52 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Tue, 1 Aug 2023 07:08:09 +0200 Subject: [PATCH] fixed first control planed depending on kustomization_backup --- control_planes.tf | 2 +- init.tf | 31 +------------------------------ kustomization_backup.tf | 15 +-------------- locals.tf | 30 ++++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/control_planes.tf b/control_planes.tf index 355533f2..cd5bf328 100644 --- a/control_planes.tf +++ b/control_planes.tf @@ -143,7 +143,7 @@ resource "null_resource" "control_planes" { inline = [ "systemctl start k3s 2> /dev/null", <<-EOT - timeout 120 bash < /dev/null; do systemctl start k3s 2> /dev/null echo "Waiting for the k3s server to start..." diff --git a/init.tf b/init.tf index 8d8624ed..79cfb9a8 100644 --- a/init.tf +++ b/init.tf @@ -124,36 +124,7 @@ resource "null_resource" "kustomization" { # Upload kustomization.yaml, containing Hetzner CSI & CSM, as well as kured. provisioner "file" { - content = yamlencode({ - apiVersion = "kustomize.config.k8s.io/v1beta1" - kind = "Kustomization" - - resources = concat( - [ - "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/${local.ccm_version}/ccm-networks.yaml", - "https://github.com/weaveworks/kured/releases/download/${local.kured_version}/kured-${local.kured_version}-dockerhub.yaml", - "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml", - ], - var.disable_hetzner_csi ? [] : [ - "hcloud-csi.yml" - ], - lookup(local.ingress_controller_install_resources, local.ingress_controller, []), - lookup(local.cni_install_resources, var.cni_plugin, []), - var.enable_longhorn ? ["longhorn.yaml"] : [], - var.enable_csi_driver_smb ? ["csi-driver-smb.yaml"] : [], - var.enable_cert_manager || var.enable_rancher ? ["cert_manager.yaml"] : [], - var.enable_rancher ? ["rancher.yaml"] : [], - var.rancher_registration_manifest_url != "" ? [var.rancher_registration_manifest_url] : [] - ), - patchesStrategicMerge = concat( - [ - file("${path.module}/kustomize/system-upgrade-controller.yaml"), - "kured.yaml", - "ccm.yaml", - ], - lookup(local.cni_install_resource_patches, var.cni_plugin, []) - ) - }) + content = local.kustomization_backup_yaml destination = "/var/post_install/kustomization.yaml" } diff --git a/kustomization_backup.tf b/kustomization_backup.tf index 58604204..cb6b2e34 100644 --- a/kustomization_backup.tf +++ b/kustomization_backup.tf @@ -1,19 +1,6 @@ -data "remote_file" "kustomization_backup" { - conn { - host = module.control_planes[keys(module.control_planes)[0]].ipv4_address - port = var.ssh_port - user = "root" - private_key = var.ssh_private_key - agent = var.ssh_private_key == null - } - path = "/var/post_install/kustomization.yaml" - - depends_on = [null_resource.kustomization] -} - resource "local_file" "kustomization_backup" { count = var.create_kustomization ? 1 : 0 - content = data.remote_file.kustomization_backup.content + content = local.kustomization_backup_yaml filename = "${var.cluster_name}_kustomization_backup.yaml" file_permission = "600" } diff --git a/locals.tf b/locals.tf index 77b44517..8e288d3e 100644 --- a/locals.tf +++ b/locals.tf @@ -62,6 +62,36 @@ locals { ["timeout 180s /bin/sh -c 'while ! ping -c 1 ${var.address_for_connectivity_test} >/dev/null 2>&1; do echo \"Ready for k3s installation, waiting for a successful connection to the internet...\"; sleep 5; done; echo Connected'"] ) + kustomization_backup_yaml = yamlencode({ + apiVersion = "kustomize.config.k8s.io/v1beta1" + kind = "Kustomization" + + resources = concat( + [ + "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/${local.ccm_version}/ccm-networks.yaml", + "https://github.com/weaveworks/kured/releases/download/${local.kured_version}/kured-${local.kured_version}-dockerhub.yaml", + "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml", + ], + var.disable_hetzner_csi ? [] : [ + "hcloud-csi.yml" + ], + lookup(local.ingress_controller_install_resources, local.ingress_controller, []), + lookup(local.cni_install_resources, var.cni_plugin, []), + var.enable_longhorn ? ["longhorn.yaml"] : [], + var.enable_csi_driver_smb ? ["csi-driver-smb.yaml"] : [], + var.enable_cert_manager || var.enable_rancher ? ["cert_manager.yaml"] : [], + var.enable_rancher ? ["rancher.yaml"] : [], + var.rancher_registration_manifest_url != "" ? [var.rancher_registration_manifest_url] : [] + ), + patchesStrategicMerge = concat( + [ + file("${path.module}/kustomize/system-upgrade-controller.yaml"), + "kured.yaml", + "ccm.yaml", + ], + lookup(local.cni_install_resource_patches, var.cni_plugin, []) + ) + }) apply_k3s_selinux = ["/sbin/semodule -v -i /usr/share/selinux/packages/k3s.pp"]