From 0b13f900e10f9f40efa63d9305f8ccf1ab3d414a Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Wed, 9 Feb 2022 13:03:31 +0100 Subject: [PATCH] Agents IP should not depend on servers_num --- agents.tf | 6 +++--- locals.tf | 2 +- servers.tf | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/agents.tf b/agents.tf index 61ace48..ba73c19 100644 --- a/agents.tf +++ b/agents.tf @@ -76,13 +76,13 @@ resource "hcloud_server" "agents" { } } - # Generating k3s agent config file + # Generating k3s agent config file provisioner "file" { content = yamlencode({ node-name = self.name kubelet-arg = "cloud-provider=external" flannel-iface = "eth1" - node-ip = cidrhost(hcloud_network.k3s.ip_range, 2 + var.servers_num + count.index) + node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 257 + count.index) }) destination = "/etc/rancher/k3s/config.yaml" @@ -114,7 +114,7 @@ resource "hcloud_server" "agents" { network { network_id = hcloud_network.k3s.id - ip = cidrhost(hcloud_network.k3s.ip_range, 2 + var.servers_num + count.index) + ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 257 + count.index) } depends_on = [ diff --git a/locals.tf b/locals.tf index 63fae36..07378ec 100644 --- a/locals.tf +++ b/locals.tf @@ -1,5 +1,5 @@ locals { - first_control_plane_network_ip = cidrhost(hcloud_network.k3s.ip_range, 2) + first_control_plane_network_ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 2) hcloud_image_name = "ubuntu-20.04" ssh_public_key = trimspace(file(var.public_key)) # ssh_private_key is either the contents of var.private_key or null to use a ssh agent. diff --git a/servers.tf b/servers.tf index 9d2cbbc..7dce00a 100644 --- a/servers.tf +++ b/servers.tf @@ -68,9 +68,9 @@ resource "hcloud_server" "control_planes" { disable = "servicelb, local-storage" flannel-iface = "eth1" kubelet-arg = "cloud-provider=external" - node-ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) - advertise-address = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) - tls-san = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) + node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) + advertise-address = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) + tls-san = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) token = random_password.k3s_token.result node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"] }) @@ -104,7 +104,7 @@ resource "hcloud_server" "control_planes" { network { network_id = hcloud_network.k3s.id - ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) + ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) } depends_on = [