|
1 | 1 | resource "talos_machine_secrets" "this" { |
2 | | - talos_version = "v1.9" |
| 2 | + talos_version = var.talos_version |
3 | 3 | } |
4 | 4 |
|
5 | | -data "talos_machine_configuration" "this" { |
| 5 | +locals { |
| 6 | + virtual_ip = var.virtual_ip != "" ? var.virtual_ip : var.control_planes[0].server_ip |
| 7 | + cluster_endpoint = "https://${local.virtual_ip}:6443" |
| 8 | +} |
| 9 | + |
| 10 | +data "talos_machine_configuration" "control_plane" { |
| 11 | + for_each = { for control_plane in var.control_planes : control_plane.name => control_plane } |
| 12 | + talos_version = var.talos_version |
6 | 13 | cluster_name = var.cluster_name |
7 | 14 | machine_type = "controlplane" |
8 | | - cluster_endpoint = "https://${var.server_ip}:6443" |
| 15 | + cluster_endpoint = local.cluster_endpoint |
9 | 16 | machine_secrets = talos_machine_secrets.this.machine_secrets |
10 | | - talos_version = "v1.9" |
11 | 17 | config_patches = [ |
12 | | - templatefile("${path.module}/templates/controlplane_patch.yml", {}) |
| 18 | + templatefile("${path.module}/base_config.yml", { hostname = each.value.name }) |
13 | 19 | ] |
14 | 20 | } |
15 | 21 |
|
16 | | -resource "talos_machine_configuration_apply" "this" { |
| 22 | +data "talos_machine_configuration" "worker" { |
| 23 | + for_each = { for worker in var.workers : worker.name => worker } |
| 24 | + talos_version = var.talos_version |
| 25 | + cluster_name = var.cluster_name |
| 26 | + cluster_endpoint = local.cluster_endpoint |
| 27 | + machine_type = "worker" |
| 28 | + machine_secrets = talos_machine_secrets.this.machine_secrets |
| 29 | + config_patches = [ |
| 30 | + templatefile("${path.module}/base_config.yml", { hostname = each.value.name }) |
| 31 | + ] |
| 32 | +} |
| 33 | + |
| 34 | +resource "talos_machine_configuration_apply" "control_plane" { |
| 35 | + for_each = { for control_plane in var.control_planes : control_plane.name => control_plane } |
| 36 | + client_configuration = talos_machine_secrets.this.client_configuration |
| 37 | + machine_configuration_input = data.talos_machine_configuration.control_plane[each.key].machine_configuration |
| 38 | + node = each.value.server_ip |
| 39 | + config_patches = each.value.config_patches |
| 40 | +} |
| 41 | + |
| 42 | +resource "talos_machine_configuration_apply" "worker" { |
| 43 | + for_each = { for worker in var.workers : worker.name => worker } |
17 | 44 | client_configuration = talos_machine_secrets.this.client_configuration |
18 | | - machine_configuration_input = data.talos_machine_configuration.this.machine_configuration |
19 | | - node = var.server_ip |
20 | | - config_patches = var.config_patches |
| 45 | + machine_configuration_input = data.talos_machine_configuration.worker[each.key].machine_configuration |
| 46 | + node = each.value.server_ip |
| 47 | + config_patches = each.value.config_patches |
21 | 48 | } |
22 | 49 |
|
23 | 50 | data "talos_client_configuration" "this" { |
24 | 51 | cluster_name = var.cluster_name |
25 | 52 | client_configuration = talos_machine_secrets.this.client_configuration |
26 | 53 | endpoints = [ |
27 | | - var.server_ip |
| 54 | + for control_plane in var.control_planes : control_plane.server_ip |
28 | 55 | ] |
29 | 56 | } |
30 | 57 |
|
31 | 58 | resource "talos_machine_bootstrap" "this" { |
32 | | - depends_on = [talos_machine_configuration_apply.this] |
| 59 | + depends_on = [talos_machine_configuration_apply.control_plane] |
33 | 60 | client_configuration = talos_machine_secrets.this.client_configuration |
34 | | - endpoint = var.server_ip |
35 | | - node = var.server_ip |
| 61 | + endpoint = var.control_planes[0].server_ip |
| 62 | + node = var.control_planes[0].server_ip |
36 | 63 | } |
37 | 64 |
|
38 | 65 | resource "talos_cluster_kubeconfig" "this" { |
39 | 66 | client_configuration = talos_machine_secrets.this.client_configuration |
40 | | - node = var.server_ip |
| 67 | + node = var.control_planes[0].server_ip |
41 | 68 | } |
42 | 69 |
|
43 | | -# data "talos_cluster_health" "this" { |
44 | | -# client_configuration = data.talos_client_configuration.this.client_configuration |
45 | | -# control_plane_nodes = [var.server_ip] |
46 | | -# endpoints = data.talos_client_configuration.this.endpoints |
47 | | -# skip_kubernetes_checks = true |
48 | | -# } |
49 | | - |
50 | 70 | data "http" "talos_health" { |
51 | | - url = "https://${var.server_ip}:6443/version" |
| 71 | + url = "${local.cluster_endpoint}/version" |
52 | 72 | insecure = true |
53 | 73 | retry { |
54 | | - attempts = 20 |
| 74 | + attempts = 60 |
55 | 75 | min_delay_ms = 5000 |
56 | 76 | max_delay_ms = 5000 |
57 | 77 | } |
58 | | - depends_on = [ |
59 | | - talos_machine_bootstrap.this, |
60 | | - ] |
| 78 | + depends_on = [talos_machine_bootstrap.this] |
61 | 79 | } |
0 commit comments