From e68ac2c2a1a80a5fbfacefc4c37243c3940ed547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joost=20D=C3=B6bken?= Date: Mon, 3 Jul 2023 20:52:05 +0200 Subject: [PATCH] replace the deprecated data template_file with templatefile (#42) --- .gitignore | 1 + modules/cluster/main.tf | 12 ++-------- modules/firewall/main.tf | 12 ++-------- modules/kubernetes/kubeadm_join.tf | 10 +------- modules/kubernetes/main.tf | 37 +++++------------------------- 5 files changed, 12 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 0bbd7f8..9aa2df9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store # Local .terraform directories **/.terraform/* **/.terraform* diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 9c8fa5b..ef17b3c 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -25,7 +25,7 @@ resource "hcloud_server" "control_plane_node" { } provisioner "file" { - content = data.template_file.floating_ip.rendered + content = templatefile("${path.module}/files/60-floating-ip.cfg", { loadbalancer_ip = var.loadbalancer_ip }) destination = "/etc/network/interfaces.d/60-floating-ip.cfg" } @@ -58,7 +58,7 @@ resource "hcloud_server" "worker_node" { } provisioner "file" { - content = data.template_file.floating_ip.rendered + content = templatefile("${path.module}/files/60-floating-ip.cfg", { loadbalancer_ip = var.loadbalancer_ip }) destination = "/etc/network/interfaces.d/60-floating-ip.cfg" } @@ -88,11 +88,3 @@ resource "hcloud_server_network" "private_network" { server_id = element(local.servers.*.id, count.index) subnet_id = hcloud_network_subnet.kubernetes_subnet.id } - -data "template_file" "floating_ip" { - template = file("${path.module}/files/60-floating-ip.cfg") - - vars = { - loadbalancer_ip = var.loadbalancer_ip - } -} diff --git a/modules/firewall/main.tf b/modules/firewall/main.tf index d362e6d..f0174dd 100644 --- a/modules/firewall/main.tf +++ b/modules/firewall/main.tf @@ -12,7 +12,7 @@ resource "null_resource" "firewall" { count = length(var.connections) triggers = { - template = data.template_file.ufw.rendered + template = templatefile("${path.module}/scripts/ufw.sh", { subnet_ip_range = var.subnet_ip_range }) } connection { @@ -23,15 +23,7 @@ resource "null_resource" "firewall" { provisioner "remote-exec" { inline = [ - data.template_file.ufw.rendered + templatefile("${path.module}/scripts/ufw.sh", { subnet_ip_range = var.subnet_ip_range }) ] } } - -data "template_file" "ufw" { - template = file("${path.module}/scripts/ufw.sh") - - vars = { - subnet_ip_range = var.subnet_ip_range - } -} diff --git a/modules/kubernetes/kubeadm_join.tf b/modules/kubernetes/kubeadm_join.tf index 5ca18b1..0d21116 100644 --- a/modules/kubernetes/kubeadm_join.tf +++ b/modules/kubernetes/kubeadm_join.tf @@ -32,15 +32,7 @@ resource "null_resource" "kubeadm_join" { provisioner "remote-exec" { inline = [ - data.template_file.worker.rendered + templatefile("${path.module}/scripts/worker.sh", { control_plane_private_ip = local.control_plane_private_ip }) ] } } - -data "template_file" "worker" { - template = file("${path.module}/scripts/worker.sh") - - vars = { - control_plane_private_ip = local.control_plane_private_ip - } -} diff --git a/modules/kubernetes/main.tf b/modules/kubernetes/main.tf index b2a88ee..87c2c81 100644 --- a/modules/kubernetes/main.tf +++ b/modules/kubernetes/main.tf @@ -45,12 +45,15 @@ resource "null_resource" "install" { provisioner "remote-exec" { inline = [ - element(data.template_file.install.*.rendered, count.index) + templatefile("${path.module}/scripts/install.sh", { kubernetes_version = var.kubernetes_version }) ] } provisioner "file" { - content = data.template_file.access_tokens.rendered + content = templatefile("${path.module}/files/access_tokens.yaml", { + hcloud_token = var.hcloud_token, + network_id = var.network_id + }) destination = "/tmp/access_tokens.yaml" } @@ -71,39 +74,11 @@ resource "null_resource" "install" { provisioner "remote-exec" { inline = [ - count.index < length(var.control_plane_nodes) ? data.template_file.control_plane.rendered : "echo skip" + count.index < length(var.control_plane_nodes) ? templatefile("${path.module}/scripts/control_plane.sh", { kubernetes_version = var.kubernetes_version, control_plane_ip = local.control_plane_ip, cluster_name = var.cluster_name }) : "echo skip" ] } } -data "template_file" "install" { - count = length(local.connections) - template = file("${path.module}/scripts/install.sh") - - vars = { - kubernetes_version = var.kubernetes_version - } -} - -data "template_file" "control_plane" { - template = file("${path.module}/scripts/control_plane.sh") - - vars = { - kubernetes_version = var.kubernetes_version - control_plane_ip = local.control_plane_ip - cluster_name = var.cluster_name - } -} - -data "template_file" "access_tokens" { - template = file("${path.module}/files/access_tokens.yaml") - - vars = { - hcloud_token = var.hcloud_token - network_id = var.network_id - } -} - module "kubeconfig" { source = "matti/resource/shell" depends_on = [null_resource.kubeadm_join]