1- locals {
2- cp = [
3- for i in range (1 ) : format (" %s-%d" , " cp" , i)
4- ]
5- }
6-
71resource "digitalocean_loadbalancer" "cp" {
82 name = " rnd-${ local . prefix } -controlplane"
93 region = " fra1"
@@ -54,13 +48,38 @@ resource "digitalocean_record" "endpoint" {
5448 ttl = 30
5549}
5650
51+ resource "digitalocean_droplet" "cp" {
52+ name = " rnd-${ local . prefix } -spectrum-cp"
53+ size = " s-4vcpu-8gb"
54+ image = data. digitalocean_image . talos . id
55+ region = " fra1"
56+ vpc_uuid = data. digitalocean_vpc . spectrum . id
57+ user_data = data. talos_machine_configuration . cp . machine_configuration
58+
59+ ssh_keys = [
60+ digitalocean_ssh_key . spectrum . id
61+ ]
62+
63+ tags = [
64+ local . prefix ,
65+ " ${ local . prefix } -controlplane" ,
66+ ]
67+ }
68+
69+ resource "digitalocean_record" "cp" {
70+ name = " cp"
71+ value = digitalocean_droplet. cp . ipv4_address
72+ domain = digitalocean_domain. spectrum . id
73+ type = " A"
74+ ttl = 30
75+ }
76+
77+
5778resource "talos_machine_secrets" "this" {
5879 talos_version = " v1.8"
5980}
6081
6182data "talos_machine_configuration" "cp" {
62- for_each = { for index , name in local . cp : name => index }
63-
6483 cluster_name = terraform. workspace
6584 machine_type = " controlplane"
6685 cluster_endpoint = " https://${ local . loadbalancer_dns } :6443"
@@ -69,20 +88,20 @@ data "talos_machine_configuration" "cp" {
6988 config_patches = [
7089 templatefile (" ${ path . module } /templates/controlplane_patch.yml" , {
7190 loadbalancerdns = " kube.${ local . prefix } .fluence.dev"
72- loadbalancerip = digitalocean_loadbalancer.cp.ip
73- hostdns = " ${ each . key } .${ local . prefix } .fluence.dev" ,
91+ hostdns = " cp.${ local . prefix } .fluence.dev" ,
7492 subnet = data.digitalocean_vpc.spectrum.ip_range,
75- branch = var.github_branch
76- dotoken = base64encode (data. vault_generic_secret . spectrum . data . token )
77- domain = " ${ local . prefix } .fluence.dev"
78- prefix = local.prefix
79- pr_url = var.github_pr_url
8093 docker_username = data.vault_generic_secret.docker.data.username
8194 docker_password = data.vault_generic_secret.docker.data.password
8295 })
8396 ]
8497}
8598
99+ resource "talos_machine_configuration_apply" "this" {
100+ client_configuration = talos_machine_secrets. this . client_configuration
101+ machine_configuration_input = data. talos_machine_configuration . cp . machine_configuration
102+ node = digitalocean_droplet. cp . ipv4_address
103+ }
104+
86105data "talos_client_configuration" "this" {
87106 cluster_name = terraform. workspace
88107 client_configuration = talos_machine_secrets. this . client_configuration
@@ -91,61 +110,38 @@ data "talos_client_configuration" "this" {
91110 ]
92111}
93112
94- resource "digitalocean_droplet" "cp" {
95- for_each = { for index , name in local . cp : name => index }
96-
97- name = " rnd-${ local . prefix } -spectrum-${ each . key } "
98- size = " s-4vcpu-8gb"
99- image = data. digitalocean_image . talos . id
100- region = " fra1"
101- vpc_uuid = data. digitalocean_vpc . spectrum . id
102- user_data = data. talos_machine_configuration . cp [each . key ]. machine_configuration
103-
104- ssh_keys = [
105- digitalocean_ssh_key . spectrum . id
106- ]
107-
108- tags = [
109- local . prefix ,
110- " ${ local . prefix } -controlplane" ,
111- ]
112- }
113-
114- resource "digitalocean_record" "cp" {
115- for_each = { for index , name in local . cp : name => index }
116-
117- name = each. key
118- value = digitalocean_droplet. cp [each . key ]. ipv4_address
119- domain = digitalocean_domain. spectrum . id
120- type = " A"
121- ttl = 30
122- }
123-
124113resource "talos_machine_bootstrap" "this" {
125114 client_configuration = talos_machine_secrets. this . client_configuration
126- endpoint = digitalocean_droplet. cp [ " cp-0 " ] . ipv4_address
127- node = digitalocean_droplet. cp [ " cp-0 " ] . ipv4_address
115+ endpoint = digitalocean_droplet. cp . ipv4_address
116+ node = digitalocean_droplet. cp . ipv4_address
128117 timeouts = {
129118 create = " 3m"
130119 }
131120
132121 lifecycle {
133122 replace_triggered_by = [
134- digitalocean_droplet . cp [ " cp-0 " ] . id
123+ digitalocean_droplet . cp . id
135124 ]
136125 }
137126}
138127
139128resource "talos_cluster_kubeconfig" "this" {
140129 client_configuration = talos_machine_secrets. this . client_configuration
141- node = digitalocean_droplet. cp [ " cp-0 " ] . ipv4_address
130+ node = digitalocean_droplet. cp . ipv4_address
142131 timeouts = {
143132 create = " 3m"
144133 }
145134}
146135
147- data "talos_cluster_health" "health" {
148- client_configuration = data. talos_client_configuration . this . client_configuration
149- control_plane_nodes = [for droplet in digitalocean_droplet . cp : droplet . ipv4_address_private ]
150- endpoints = data. talos_client_configuration . this . endpoints
136+ data "http" "talos_health" {
137+ url = " https://${ digitalocean_record . endpoint . fqdn } :6443/version"
138+ insecure = true
139+ retry {
140+ attempts = 20
141+ min_delay_ms = 5000
142+ max_delay_ms = 5000
143+ }
144+ depends_on = [
145+ talos_machine_bootstrap . this ,
146+ ]
151147}
0 commit comments