From 35302de488d75c60d61fdc826af68057ade8eb03 Mon Sep 17 00:00:00 2001 From: Stephan Feurer Date: Fri, 13 Sep 2024 14:29:51 +0200 Subject: [PATCH] Support creating multiple affinit groups A new variable affinity_group_capacity defines the capacity of an affinity group. --- modules/node-group/main.tf | 6 ++++-- modules/node-group/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/node-group/main.tf b/modules/node-group/main.tf index ff5f7bc..c30148c 100644 --- a/modules/node-group/main.tf +++ b/modules/node-group/main.tf @@ -1,6 +1,8 @@ locals { disk_size = var.root_disk_size + var.data_disk_size + var.storage_disk_size + anti_affinity_group_count = var.affinity_group_capacity > 0 ? (var.affinity_group_capacity / var.node_count): 1 + ignition_source = { "bootstrap" = "${trimsuffix(var.bootstrap_bucket, "/")}/bootstrap.ign" "master" = "https://${var.api_int}:22623/config/master" @@ -161,7 +163,7 @@ resource "random_id" "node_id" { } resource "exoscale_anti_affinity_group" "anti_affinity_group" { - count = var.node_count > 0 ? 1 : 0 + count = var.node_count != 0 ? local.anti_affinity_group_count : 0 name = "${var.cluster_id}_${var.role}" description = "${var.cluster_id} ${var.role} nodes" } @@ -181,7 +183,7 @@ resource "exoscale_compute_instance" "nodes" { security_group_ids = var.security_group_ids anti_affinity_group_ids = concat( - [exoscale_anti_affinity_group.anti_affinity_group[0].id], + [exoscale_anti_affinity_group.anti_affinity_group[floor(count.index / local.anti_affinity_capacity)].id], var.additional_affinity_group_ids ) diff --git a/modules/node-group/variables.tf b/modules/node-group/variables.tf index 041a9ec..d87695b 100644 --- a/modules/node-group/variables.tf +++ b/modules/node-group/variables.tf @@ -120,3 +120,9 @@ variable "deploy_target_id" { default = "" description = "ID of special deployment target, e.g. dedicated hypervisors" } + +variable "affinity_group_capacity" { + type = number + default = 0 + description = "Capacity of the affinity group, e.g. when using dedicated hypervisors, default: 0 (unlimited)" +} diff --git a/variables.tf b/variables.tf index 241be83..a436ec8 100644 --- a/variables.tf +++ b/variables.tf @@ -193,6 +193,12 @@ variable "deploy_target_id" { description = "ID of special deployment target, e.g. dedicated hypervisors" } +variable "affinity_group_capacity" { + type = number + default = 0 + description = "Capacity of the affinity group, e.g. when using dedicated hypervisors, default: 0 (unlimited)" +} + variable "ignition_ca" { type = string }