From 39e06dd30404e90bee74e5374120517089c78de4 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Mon, 25 Mar 2024 18:00:39 +0530 Subject: [PATCH] chore: reduce complexity There is no need to create machine config for each instance in a worker group. We only need machine configs for each set of worker group. So this cleans up code to use `m` instead of `m * n` numbers of worker configs. Signed-off-by: Noel Georgi --- examples/terraform/aws/main.tf | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/terraform/aws/main.tf b/examples/terraform/aws/main.tf index 28905ae..4727c0a 100644 --- a/examples/terraform/aws/main.tf +++ b/examples/terraform/aws/main.tf @@ -325,7 +325,7 @@ data "talos_machine_configuration" "controlplane" { } data "talos_machine_configuration" "worker_group" { - for_each = merge([for info in var.worker_groups : { for index in range(0, info.num_instances) : "${info.name}.${index}" => info }]...) + for_each = merge([for info in var.worker_groups : { "${info.name}" = info }]...) cluster_name = var.cluster_name cluster_endpoint = "https://${module.elb_k8s_elb.elb_dns_name}" @@ -353,10 +353,19 @@ resource "talos_machine_configuration_apply" "controlplane" { } resource "talos_machine_configuration_apply" "worker_group" { - for_each = merge([for info in var.worker_groups : { for index in range(0, info.num_instances) : "${info.name}.${index}" => info }]...) + for_each = merge([ + for info in var.worker_groups : { + for index in range(0, info.num_instances) : + "${info.name}.${index}" => { + name = info.name, + public_ip = module.talos_worker_group["${info.name}.${index}"].public_ip, + private_ip = module.talos_worker_group["${info.name}.${index}"].private_ip + } + } + ]...) client_configuration = talos_machine_secrets.this.client_configuration - machine_configuration_input = data.talos_machine_configuration.worker_group[each.key].machine_configuration + machine_configuration_input = data.talos_machine_configuration.worker_group[each.value.name].machine_configuration endpoint = module.talos_worker_group[each.key].public_ip node = module.talos_worker_group[each.key].private_ip } @@ -384,7 +393,11 @@ data "talos_cluster_kubeconfig" "this" { } data "talos_cluster_health" "this" { - depends_on = [data.talos_cluster_kubeconfig.this] + depends_on = [ + talos_machine_configuration_apply.controlplane, + talos_machine_configuration_apply.worker_group, + data.talos_cluster_kubeconfig.this + ] client_configuration = talos_machine_secrets.this.client_configuration endpoints = module.talos_control_plane_nodes.*.public_ip