Skip to content

Commit

Permalink
ci: refine talos terraform script
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Chiu <yang.chiu@suse.com>
  • Loading branch information
yangchiu committed Nov 29, 2024
1 parent f28fcf4 commit 6f3a630
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions test_framework/terraform/aws/talos/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ data "talos_machine_configuration" "controlplane" {

depends_on = [ aws_instance.lh_aws_instance_controlplane ]

count = var.lh_aws_instance_count_controlplane

cluster_name = "lh-tests-cluster"
cluster_endpoint = "https://${aws_instance.lh_aws_instance_controlplane[0].public_ip}:6443"
machine_type = "controlplane"
Expand All @@ -208,8 +206,6 @@ data "talos_machine_configuration" "worker" {

depends_on = [ aws_instance.lh_aws_instance_controlplane ]

count = var.lh_aws_instance_count_worker

cluster_name = "lh-tests-cluster"
cluster_endpoint = "https://${aws_instance.lh_aws_instance_controlplane[0].public_ip}:6443"
machine_type = "worker"
Expand All @@ -219,15 +215,15 @@ data "talos_machine_configuration" "worker" {
docs = false
examples = false
config_patches = [
file("${path.module}/talos-patch.yaml")
file("${path.module}/talos-patch-worker.yaml")
]
}

resource "talos_machine_configuration_apply" "controlplane" {
count = var.lh_aws_instance_count_controlplane

client_configuration = talos_machine_secrets.machine_secrets.client_configuration
machine_configuration_input = data.talos_machine_configuration.controlplane[count.index].machine_configuration
machine_configuration_input = data.talos_machine_configuration.controlplane.machine_configuration
endpoint = aws_instance.lh_aws_instance_controlplane[count.index].public_ip
node = aws_instance.lh_aws_instance_controlplane[count.index].private_ip
}
Expand All @@ -236,7 +232,7 @@ resource "talos_machine_configuration_apply" "worker" {
count = var.lh_aws_instance_count_worker

client_configuration = talos_machine_secrets.machine_secrets.client_configuration
machine_configuration_input = data.talos_machine_configuration.worker[count.index].machine_configuration
machine_configuration_input = data.talos_machine_configuration.worker.machine_configuration
endpoint = aws_instance.lh_aws_instance_worker[count.index].public_ip
node = aws_instance.lh_aws_instance_worker[count.index].private_ip
}
Expand All @@ -260,15 +256,28 @@ resource "local_file" "talosconfig" {
filename = "talos_k8s_config"
}

data "talos_cluster_kubeconfig" "this" {
resource "talos_cluster_kubeconfig" "this" {
depends_on = [talos_machine_bootstrap.this]

client_configuration = talos_machine_secrets.machine_secrets.client_configuration
endpoint = aws_instance.lh_aws_instance_controlplane[0].public_ip
endpoint = aws_instance.lh_aws_instance_controlplane.0.public_ip
node = aws_instance.lh_aws_instance_controlplane.0.private_ip
}

resource "local_file" "kubeconfig" {
content = nonsensitive(data.talos_cluster_kubeconfig.this.kubeconfig_raw)
content = nonsensitive(talos_cluster_kubeconfig.this.kubeconfig_raw)
filename = "kubeconfig"
}

data "talos_cluster_health" "this" {
depends_on = [
talos_machine_configuration_apply.controlplane,
talos_machine_configuration_apply.worker,
talos_cluster_kubeconfig.this
]

client_configuration = talos_machine_secrets.machine_secrets.client_configuration
endpoints = aws_instance.lh_aws_instance_controlplane.*.public_ip
control_plane_nodes = aws_instance.lh_aws_instance_controlplane.*.private_ip
worker_nodes = aws_instance.lh_aws_instance_worker.*.private_ip
}

0 comments on commit 6f3a630

Please sign in to comment.