Skip to content

Commit

Permalink
chore: reduce complexity
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
frezbo committed Mar 25, 2024
1 parent e540cbf commit 39e06dd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions examples/terraform/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39e06dd

Please sign in to comment.