Skip to content

Commit

Permalink
replace the deprecated data template_file with templatefile (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
JWDobken authored Jul 3, 2023
1 parent dd85ed4 commit e68ac2c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
# Local .terraform directories
**/.terraform/*
**/.terraform*
Expand Down
12 changes: 2 additions & 10 deletions modules/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
}
}
12 changes: 2 additions & 10 deletions modules/firewall/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
10 changes: 1 addition & 9 deletions modules/kubernetes/kubeadm_join.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
37 changes: 6 additions & 31 deletions modules/kubernetes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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]
Expand Down

0 comments on commit e68ac2c

Please sign in to comment.