diff --git a/agent_nodes.tf b/agent_nodes.tf index cdd9d40..d97fcd0 100644 --- a/agent_nodes.tf +++ b/agent_nodes.tf @@ -64,65 +64,13 @@ locals { } } -// Remove k3s agent if exists (used on the first run, when an immutable field changes or -// when a server will be reinstalled) -resource null_resource agents_uninstall { - for_each = var.agents - - depends_on = [null_resource.servers_install] - triggers = { - // Reinstall k3s only when specific fields changes (name or flags) - on_immutable_fields_changes = local.agents_metadata[each.key].immutable_fields_hash - on_uninstall = null_resource.servers_uninstall[local.root_server_name].id - } - - connection { - type = try(each.value.connection.type, "ssh") - - host = try(each.value.connection.host, each.value.ip) - user = try(each.value.connection.user, null) - password = try(each.value.connection.password, null) - port = try(each.value.connection.port, null) - timeout = try(each.value.connection.timeout, null) - - script_path = try(each.value.connection.script_path, null) - private_key = try(each.value.connection.private_key, null) - certificate = try(each.value.connection.certificate, null) - agent = try(each.value.connection.agent, null) - agent_identity = try(each.value.connection.agent_identity, null) - host_key = try(each.value.connection.host_key, null) - - https = try(each.value.connection.https, null) - insecure = try(each.value.connection.insecure, null) - use_ntlm = try(each.value.connection.use_ntlm, null) - cacert = try(each.value.connection.cacert, null) - - bastion_host = try(each.value.connection.bastion_host, null) - bastion_host_key = try(each.value.connection.bastion_host_key, null) - bastion_port = try(each.value.connection.bastion_port, null) - bastion_user = try(each.value.connection.bastion_user, null) - bastion_password = try(each.value.connection.bastion_password, null) - bastion_private_key = try(each.value.connection.bastion_private_key, null) - bastion_certificate = try(each.value.connection.bastion_certificate, null) - } - - // Remove old k3s installation - provisioner remote-exec { - inline = [ - "if ! command -V k3s-agent-uninstall.sh > /dev/null; then exit; fi", - "echo >&2 [WARN] K3s seems already installed on this node and will be uninstalled.", - "k3s-agent-uninstall.sh", - ] - } -} - // Install k3s agent resource null_resource agents_install { for_each = var.agents depends_on = [null_resource.servers_install] triggers = { - on_uninstall = null_resource.agents_uninstall[each.key].id + on_immutable_changes = local.agents_metadata[each.key].immutable_fields_hash on_new_version = local.k3s_version } diff --git a/server_nodes.tf b/server_nodes.tf index 8b23372..4ec2050 100644 --- a/server_nodes.tf +++ b/server_nodes.tf @@ -109,63 +109,13 @@ locals { } } -// Remove k3s server if exists (used on the first run or when an immutable field changes, -// in order to use new settings. It will reinstall the cluster.) -resource null_resource servers_uninstall { - for_each = var.servers - - depends_on = [var.depends_on_] - triggers = { - on_immutable_fields_changes = local.servers_metadata[each.key].immutable_fields_hash - } - - connection { - type = try(each.value.connection.type, "ssh") - - host = try(each.value.connection.host, each.value.ip) - user = try(each.value.connection.user, null) - password = try(each.value.connection.password, null) - port = try(each.value.connection.port, null) - timeout = try(each.value.connection.timeout, null) - - script_path = try(each.value.connection.script_path, null) - private_key = try(each.value.connection.private_key, null) - certificate = try(each.value.connection.certificate, null) - agent = try(each.value.connection.agent, null) - agent_identity = try(each.value.connection.agent_identity, null) - host_key = try(each.value.connection.host_key, null) - - https = try(each.value.connection.https, null) - insecure = try(each.value.connection.insecure, null) - use_ntlm = try(each.value.connection.use_ntlm, null) - cacert = try(each.value.connection.cacert, null) - - bastion_host = try(each.value.connection.bastion_host, null) - bastion_host_key = try(each.value.connection.bastion_host_key, null) - bastion_port = try(each.value.connection.bastion_port, null) - bastion_user = try(each.value.connection.bastion_user, null) - bastion_password = try(each.value.connection.bastion_password, null) - bastion_private_key = try(each.value.connection.bastion_private_key, null) - bastion_certificate = try(each.value.connection.bastion_certificate, null) - } - - // Remove old k3s installation - provisioner remote-exec { - inline = [ - "if ! command -V k3s-uninstall.sh > /dev/null; then exit; fi", - "echo >&2 [WARN] K3s seems already installed on this node and will be uninstalled.", - "k3s-uninstall.sh", - ] - } -} - // Install k3s server resource null_resource servers_install { for_each = var.servers depends_on = [var.depends_on_] triggers = { - on_uninstall = null_resource.servers_uninstall[each.key].id + on_immutable_changes = local.servers_metadata[each.key].immutable_fields_hash on_new_version = local.k3s_version }