placement group fix attempt

This commit is contained in:
Karim Naufal 2022-04-13 07:17:01 +02:00
parent ca8a42722c
commit 6d33e69b69
No known key found for this signature in database
GPG Key ID: 9CB4A7C28C139CA5
4 changed files with 16 additions and 10 deletions

View File

@ -9,7 +9,7 @@ module "agents" {
private_key = var.private_key private_key = var.private_key
additional_public_keys = var.additional_public_keys additional_public_keys = var.additional_public_keys
firewall_ids = [hcloud_firewall.k3s.id] firewall_ids = [hcloud_firewall.k3s.id]
placement_group_id = hcloud_placement_group.k3s.id placement_group_id = element(hcloud_placement_group.control_plane.*.id, ceil(each.value.index / 10))
location = each.value.location location = each.value.location
server_type = each.value.server_type server_type = each.value.server_type
ipv4_subnet_id = hcloud_network_subnet.subnet[[for i, v in var.agent_nodepools : i if v.name == each.value.nodepool_name][0] + length(var.control_plane_nodepools) + 1].id ipv4_subnet_id = hcloud_network_subnet.subnet[[for i, v in var.agent_nodepools : i if v.name == each.value.nodepool_name][0] + length(var.control_plane_nodepools) + 1].id

View File

@ -9,7 +9,7 @@ module "control_planes" {
private_key = var.private_key private_key = var.private_key
additional_public_keys = var.additional_public_keys additional_public_keys = var.additional_public_keys
firewall_ids = [hcloud_firewall.k3s.id] firewall_ids = [hcloud_firewall.k3s.id]
placement_group_id = hcloud_placement_group.k3s.id placement_group_id = element(hcloud_placement_group.control_plane.*.id, ceil(each.value.index / 10))
location = each.value.location location = each.value.location
server_type = each.value.server_type server_type = each.value.server_type
ipv4_subnet_id = hcloud_network_subnet.subnet[[for i, v in var.control_plane_nodepools : i if v.name == each.value.nodepool_name][0] + 1].id ipv4_subnet_id = hcloud_network_subnet.subnet[[for i, v in var.control_plane_nodepools : i if v.name == each.value.nodepool_name][0] + 1].id

View File

@ -1,6 +1,9 @@
locals { locals {
# if we are in a single cluster config, we use the default klipper lb instead of Hetzner LB # if we are in a single cluster config, we use the default klipper lb instead of Hetzner LB
is_single_node_cluster = sum(concat([for v in var.control_plane_nodepools : v.count], [0])) + sum(concat([for v in var.agent_nodepools : v.count], [0])) == 1 total_node_count = sum(concat([for v in var.control_plane_nodepools : v.count], [0])) + sum(concat([for v in var.agent_nodepools : v.count], [0]))
control_plane_count = sum(concat([for v in var.control_plane_nodepools : v.count], [0]))
agent_count = sum(concat([for v in var.agent_nodepools : v.count], [0]))
is_single_node_cluster = local.total_node_count == 1
ssh_public_key = trimspace(file(var.public_key)) 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. # ssh_private_key is either the contents of var.private_key or null to use a ssh agent.
ssh_private_key = var.private_key == null ? null : trimspace(file(var.private_key)) ssh_private_key = var.private_key == null ? null : trimspace(file(var.private_key))

17
main.tf
View File

@ -36,13 +36,16 @@ resource "hcloud_firewall" "k3s" {
} }
} }
resource "hcloud_placement_group" "k3s" { resource "hcloud_placement_group" "control_plane" {
name = var.cluster_name count = ceil(local.control_plane_count / 10)
type = "spread" name = "${var.cluster_name}-${count.index + 1}"
labels = { type = "spread"
"provisioner" = "terraform", }
"engine" = "k3s"
} resource "hcloud_placement_group" "agent" {
count = ceil(local.agent_count / 10)
name = "${var.cluster_name}-${count.index + 1}"
type = "spread"
} }
data "hcloud_load_balancer" "traefik" { data "hcloud_load_balancer" "traefik" {