From 6739b4a493af4372e8cfca082f40f8d00246cf25 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Thu, 24 Feb 2022 01:44:56 +0100 Subject: [PATCH] added null ressouce to destroy lb --- main.tf | 17 +++++++++++++++++ modules/host/locals.tf | 1 + 2 files changed, 18 insertions(+) diff --git a/main.tf b/main.tf index 3e71a22..61bcc8b 100644 --- a/main.tf +++ b/main.tf @@ -158,3 +158,20 @@ data "hcloud_load_balancer" "traefik" { depends_on = [null_resource.kustomization] } + +resource "null_resource" "destroy_lb" { + triggers = { + token = random_password.k3s_token.result + } + + # Important when issuing terraform destroy, otherwise the LB will not let the network get deleted + provisioner "local-exec" { + when = destroy + command = <<-EOT + hcloud load-balancer delete traefik + hcloud network delete k3s + EOT + + on_failure = continue + } +} diff --git a/modules/host/locals.tf b/modules/host/locals.tf index 5a61b2a..4e32a8c 100644 --- a/modules/host/locals.tf +++ b/modules/host/locals.tf @@ -66,6 +66,7 @@ rpm --import https://rpm.rancher.io/public.key zypper refresh zypper --gpg-auto-import-keys install -y https://rpm.rancher.io/k3s/stable/common/microos/noarch/k3s-selinux-0.4-1.sle.noarch.rpm udevadm settle +exit 0 EOF }