Skip to content

Commit

Permalink
refactor: replace null_resource with terraform_data (#69)
Browse files Browse the repository at this point in the history
Closes #43

---------

Co-authored-by: simonhammes <[email protected]>
Co-authored-by: Jonas L. <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent 40b22ed commit 11cd7e2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 121 deletions.
18 changes: 0 additions & 18 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 69 additions & 91 deletions example/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions k3s_registry/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ variable "server" {
})
}

resource "null_resource" "k3s_registry" {
triggers = {
resource "terraform_data" "k3s_registry" {
triggers_replace = {
id = var.server.id
}

Expand Down
12 changes: 6 additions & 6 deletions main-setup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module "registry_control" {
private_key = tls_private_key.ssh.private_key_openssh
}

resource "null_resource" "k3sup_control" {
resource "terraform_data" "k3sup_control" {
depends_on = [module.registry_control]

triggers = {
triggers_replace = {
id = hcloud_server.control.id
ip = hcloud_server_network.control.ip
}
Expand Down Expand Up @@ -64,18 +64,18 @@ module "registry_worker" {
private_key = tls_private_key.ssh.private_key_openssh
}

resource "null_resource" "k3sup_worker" {
resource "terraform_data" "k3sup_worker" {
count = var.worker_count

depends_on = [module.registry_worker]

triggers = {
triggers_replace = {
id = hcloud_server.worker[count.index].id
ip = hcloud_server_network.worker[count.index].ip

# Wait the control-plane to be initialized, and re-join the new cluster if the
# control-plane server changed.
control_id = null_resource.k3sup_control.id
control_id = terraform_data.k3sup_control.id
}

connection {
Expand Down Expand Up @@ -105,7 +105,7 @@ resource "null_resource" "k3sup_worker" {
# Configure kubernetes

data "local_sensitive_file" "kubeconfig" {
depends_on = [null_resource.k3sup_control]
depends_on = [terraform_data.k3sup_control]
filename = local.kubeconfig_path
}

Expand Down
4 changes: 0 additions & 4 deletions providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ terraform {
source = "hashicorp/local"
version = ">= 2.5.1, < 3.0.0"
}
null = {
source = "hashicorp/null"
version = ">= 3.2.2, < 4.0.0"
}
tls = {
source = "hashicorp/tls"
version = ">= 4.0.5, < 5.0.0"
Expand Down

0 comments on commit 11cd7e2

Please sign in to comment.