diff --git a/agents.tf b/agents.tf index 0c3e4534..4c46f2b5 100644 --- a/agents.tf +++ b/agents.tf @@ -59,10 +59,10 @@ locals { ) } } -resource "null_resource" "agent_config" { +resource "terraform_data" "agent_config" { for_each = local.agent_nodes - triggers = { + triggers_replace = { agent_id = module.agents[each.key].id config = sha1(yamlencode(local.k3s-agent-config[each.key])) } @@ -85,11 +85,15 @@ resource "null_resource" "agent_config" { inline = [local.k3s_config_update_script] } } +moved { + from = null_resource.agent_config + to = terraform_data.agent_config +} -resource "null_resource" "agents" { +resource "terraform_data" "agents" { for_each = local.agent_nodes - triggers = { + triggers_replace = { agent_id = module.agents[each.key].id } @@ -123,11 +127,15 @@ resource "null_resource" "agents" { } depends_on = [ - null_resource.first_control_plane, - null_resource.agent_config, + terraform_data.first_control_plane, + terraform_data.agent_config, hcloud_network_subnet.agent ] } +moved { + from = null_resource.agents + to = terraform_data.agents +} resource "hcloud_volume" "longhorn_volume" { for_each = { for k, v in local.agent_nodes : k => v if((v.longhorn_volume_size >= 10) && (v.longhorn_volume_size <= 10240) && var.enable_longhorn) } @@ -145,10 +153,10 @@ resource "hcloud_volume" "longhorn_volume" { delete_protection = var.enable_delete_protection.volume } -resource "null_resource" "configure_longhorn_volume" { +resource "terraform_data" "configure_longhorn_volume" { for_each = { for k, v in local.agent_nodes : k => v if((v.longhorn_volume_size >= 10) && (v.longhorn_volume_size <= 10240) && var.enable_longhorn) } - triggers = { + triggers_replace = { agent_id = module.agents[each.key].id } @@ -174,6 +182,10 @@ resource "null_resource" "configure_longhorn_volume" { hcloud_volume.longhorn_volume ] } +moved { + from = null_resource.configure_longhorn_volume + to = terraform_data.configure_longhorn_volume +} resource "hcloud_floating_ip" "agents" { for_each = { for k, v in local.agent_nodes : k => v if coalesce(lookup(v, "floating_ip"), false) } @@ -191,14 +203,14 @@ resource "hcloud_floating_ip_assignment" "agents" { server_id = module.agents[each.key].id depends_on = [ - null_resource.agents + terraform_data.agents ] } -resource "null_resource" "configure_floating_ip" { +resource "terraform_data" "configure_floating_ip" { for_each = { for k, v in local.agent_nodes : k => v if coalesce(lookup(v, "floating_ip"), false) } - triggers = { + triggers_replace = { agent_id = module.agents[each.key].id floating_ip_id = hcloud_floating_ip.agents[each.key].id } @@ -234,3 +246,7 @@ resource "null_resource" "configure_floating_ip" { hcloud_floating_ip_assignment.agents ] } +moved { + from = null_resource.configure_floating_ip + to = terraform_data.configure_floating_ip +} diff --git a/autoscaler-agents.tf b/autoscaler-agents.tf index c81c2104..7d75a359 100644 --- a/autoscaler-agents.tf +++ b/autoscaler-agents.tf @@ -52,10 +52,10 @@ locals { } } -resource "null_resource" "configure_autoscaler" { +resource "terraform_data" "configure_autoscaler" { count = length(var.autoscaler_nodepools) > 0 ? 1 : 0 - triggers = { + triggers_replace = { template = local.autoscaler_yaml } connection { @@ -79,12 +79,16 @@ resource "null_resource" "configure_autoscaler" { depends_on = [ hcloud_load_balancer.cluster, - null_resource.control_planes, + terraform_data.control_planes, random_password.rancher_bootstrap, hcloud_volume.longhorn_volume, data.hcloud_image.microos_x86_snapshot ] } +moved { + from = null_resource.configure_autoscaler + to = terraform_data.configure_autoscaler +} data "cloudinit_config" "autoscaler_config" { count = length(var.autoscaler_nodepools) @@ -155,9 +159,9 @@ data "hcloud_servers" "autoscaled_nodes" { with_selector = "hcloud/node-group=${local.cluster_prefix}${each.value}" } -resource "null_resource" "autoscaled_nodes_registries" { +resource "terraform_data" "autoscaled_nodes_registries" { for_each = local.autoscaled_nodes - triggers = { + triggers_replace = { registries = var.k3s_registries } @@ -178,3 +182,7 @@ resource "null_resource" "autoscaled_nodes_registries" { inline = [local.k3s_registries_update_script] } } +moved { + from = null_resource.autoscaled_nodes_registries + to = terraform_data.autoscaled_nodes_registries +} diff --git a/control_planes.tf b/control_planes.tf index 4c5bdd29..ed89daf5 100644 --- a/control_planes.tf +++ b/control_planes.tf @@ -122,10 +122,10 @@ locals { ) } } -resource "null_resource" "control_plane_config" { +resource "terraform_data" "control_plane_config" { for_each = local.control_plane_nodes - triggers = { + triggers_replace = { control_plane_id = module.control_planes[each.key].id config = sha1(yamlencode(local.k3s-config[each.key])) } @@ -149,16 +149,20 @@ resource "null_resource" "control_plane_config" { } depends_on = [ - null_resource.first_control_plane, + terraform_data.first_control_plane, hcloud_network_subnet.control_plane ] } +moved { + from = null_resource.control_plane_config + to = terraform_data.control_plane_config +} -resource "null_resource" "authentication_config" { +resource "terraform_data" "authentication_config" { for_each = local.control_plane_nodes - triggers = { + triggers_replace = { control_plane_id = module.control_planes[each.key].id authentication_config = sha1(var.authentication_config) } @@ -181,15 +185,19 @@ resource "null_resource" "authentication_config" { } depends_on = [ - null_resource.first_control_plane, + terraform_data.first_control_plane, hcloud_network_subnet.control_plane ] } +moved { + from = null_resource.authentication_config + to = terraform_data.authentication_config +} -resource "null_resource" "control_planes" { +resource "terraform_data" "control_planes" { for_each = local.control_plane_nodes - triggers = { + triggers_replace = { control_plane_id = module.control_planes[each.key].id } @@ -226,9 +234,13 @@ resource "null_resource" "control_planes" { } depends_on = [ - null_resource.first_control_plane, - null_resource.control_plane_config, - null_resource.authentication_config, + terraform_data.first_control_plane, + terraform_data.control_plane_config, + terraform_data.authentication_config, hcloud_network_subnet.control_plane ] } +moved { + from = null_resource.control_planes + to = terraform_data.control_planes +} diff --git a/data.tf b/data.tf index 44fa13a7..376aeaea 100644 --- a/data.tf +++ b/data.tf @@ -32,7 +32,7 @@ data "github_release" "calico" { # count = local.has_external_load_balancer ? 0 : 1 # name = var.cluster_name -# depends_on = [null_resource.kustomization] +# depends_on = [terraform_data.kustomization] # } data "hcloud_ssh_keys" "keys_by_selector" { diff --git a/docs/terraform.md b/docs/terraform.md index 21bc2e15..aa619bc9 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -58,19 +58,19 @@ | [local_file.nginx_values](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | [local_file.traefik_values](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | [local_sensitive_file.kubeconfig](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource | -| [null_resource.agent_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.agents](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.authentication_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.autoscaled_nodes_registries](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.configure_autoscaler](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.configure_floating_ip](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.configure_longhorn_volume](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.control_plane_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.control_planes](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.first_control_plane](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.kustomization](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.kustomization_user](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.kustomization_user_deploy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.agent_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.agents](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.authentication_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.autoscaled_nodes_registries](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.configure_autoscaler](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.configure_floating_ip](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.configure_longhorn_volume](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.control_plane_config](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.control_planes](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.first_control_plane](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.kustomization](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.kustomization_user](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [terraform_data.kustomization_user_deploy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [random_password.k3s_token](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource | | [random_password.rancher_bootstrap](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource | | [cloudinit_config.autoscaler_config](https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs/data-sources/config) | data source | diff --git a/examples/kustomization_user_deploy/README.md b/examples/kustomization_user_deploy/README.md index d8284f2b..37cf8512 100644 --- a/examples/kustomization_user_deploy/README.md +++ b/examples/kustomization_user_deploy/README.md @@ -58,15 +58,15 @@ To check the existing kustomization, you can run the following command: ``` $ terraform state list | grep kustom ... - module.kube-hetzner.null_resource.kustomization - module.kube-hetzner.null_resource.kustomization_user["demo-config-map.yaml.tpl"] - module.kube-hetzner.null_resource.kustomization_user["demo-pod.yaml.tpl"] - module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] + module.kube-hetzner.terraform_data.kustomization + module.kube-hetzner.terraform_data.kustomization_user["demo-config-map.yaml.tpl"] + module.kube-hetzner.terraform_data.kustomization_user["demo-pod.yaml.tpl"] + module.kube-hetzner.terraform_data.kustomization_user["kustomization.yaml.tpl"] ... ``` If you want to rerun just the kustomization part, you can use the following command: ``` -terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve +terraform apply -replace='module.kube-hetzner.terraform_data.kustomization_user["kustomization.yaml.tpl"]' --auto-approve ``` diff --git a/init.tf b/init.tf index d9c5eac1..477460c6 100644 --- a/init.tf +++ b/init.tf @@ -20,7 +20,7 @@ resource "hcloud_load_balancer" "cluster" { } -resource "null_resource" "first_control_plane" { +resource "terraform_data" "first_control_plane" { connection { user = "root" private_key = var.ssh_private_key @@ -102,6 +102,10 @@ resource "null_resource" "first_control_plane" { hcloud_network_subnet.control_plane ] } +moved { + from = null_resource.first_control_plane + to = terraform_data.first_control_plane +} # Needed for rancher setup resource "random_password" "rancher_bootstrap" { @@ -111,8 +115,8 @@ resource "random_password" "rancher_bootstrap" { } # This is where all the setup of Kubernetes components happen -resource "null_resource" "kustomization" { - triggers = { +resource "terraform_data" "kustomization" { + triggers_replace = { # Redeploy helm charts when the underlying values change helm_values_yaml = join("---\n", [ local.traefik_values, @@ -373,8 +377,12 @@ resource "null_resource" "kustomization" { depends_on = [ hcloud_load_balancer.cluster, - null_resource.control_planes, + terraform_data.control_planes, random_password.rancher_bootstrap, hcloud_volume.longhorn_volume ] } +moved { + from = null_resource.kustomization + to = terraform_data.kustomization +} diff --git a/kubeconfig.tf b/kubeconfig.tf index 228f98a6..227bc907 100644 --- a/kubeconfig.tf +++ b/kubeconfig.tf @@ -8,7 +8,7 @@ data "remote_file" "kubeconfig" { } path = "/etc/rancher/k3s/k3s.yaml" - depends_on = [null_resource.control_planes[0]] + depends_on = [terraform_data.control_planes[0]] } locals { diff --git a/kustomization_user.tf b/kustomization_user.tf index 9fa13943..eaa0072c 100644 --- a/kustomization_user.tf +++ b/kustomization_user.tf @@ -2,7 +2,7 @@ locals { user_kustomization_templates = try(fileset("extra-manifests", "**/*.yaml.tpl"), toset([])) } -resource "null_resource" "kustomization_user" { +resource "terraform_data" "kustomization_user" { for_each = local.user_kustomization_templates connection { @@ -24,16 +24,20 @@ resource "null_resource" "kustomization_user" { destination = replace("/var/user_kustomize/${each.key}", ".yaml.tpl", ".yaml") } - triggers = { + triggers_replace = { manifest_sha1 = "${sha1(templatefile("extra-manifests/${each.key}", var.extra_kustomize_parameters))}" } depends_on = [ - null_resource.kustomization + terraform_data.kustomization ] } +moved { + from = null_resource.kustomization_user + to = terraform_data.kustomization_user +} -resource "null_resource" "kustomization_user_deploy" { +resource "terraform_data" "kustomization_user_deploy" { count = length(local.user_kustomization_templates) > 0 ? 1 : 0 connection { @@ -57,11 +61,15 @@ resource "null_resource" "kustomization_user_deploy" { lifecycle { replace_triggered_by = [ - null_resource.kustomization_user + terraform_data.kustomization_user ] } depends_on = [ - null_resource.kustomization_user + terraform_data.kustomization_user ] } +moved { + from = null_resource.kustomization_user_deploy + to = terraform_data.kustomization_user_deploy +} diff --git a/modules/host/main.tf b/modules/host/main.tf index b1973b53..22e930c9 100644 --- a/modules/host/main.tf +++ b/modules/host/main.tf @@ -94,8 +94,8 @@ resource "hcloud_server" "server" { } -resource "null_resource" "registries" { - triggers = { +resource "terraform_data" "registries" { + triggers_replace = { registries = var.k3s_registries } @@ -118,6 +118,10 @@ resource "null_resource" "registries" { depends_on = [hcloud_server.server] } +moved { + from = null_resource.registries + to = terraform_data.registries +} resource "hcloud_rdns" "server" { count = var.base_domain != "" ? 1 : 0 @@ -154,8 +158,8 @@ data "cloudinit_config" "config" { } } -resource "null_resource" "zram" { - triggers = { +resource "terraform_data" "zram" { + triggers_replace = { zram_size = var.zram_size } @@ -232,3 +236,7 @@ WantedBy=multi-user.target depends_on = [hcloud_server.server] } +moved { + from = null_resource.zram + to = terraform_data.zram +} diff --git a/versions.tf b/versions.tf index e12b76e5..7aa9f75c 100644 --- a/versions.tf +++ b/versions.tf @@ -1,5 +1,5 @@ terraform { - required_version = ">= 1.5.0" + required_version = ">= 1.9.0" required_providers { github = { source = "integrations/github"