@@ -121,8 +121,8 @@ module "talos_control_plane_nodes" {
121121 name = " ${ var . cluster_name } -control-plane-${ count . index } "
122122 ami = data. aws_ami . talos . id
123123 instance_type = var. control_plane . instance_type
124- subnet_id = var . use_private_ips_only ? element (data . aws_subnets . private . ids , count . index ) : element (data. aws_subnets . public . ids , count. index )
125- associate_public_ip_address = ! var . use_private_ips_only
124+ subnet_id = element (data. aws_subnets . public . ids , count. index )
125+ associate_public_ip_address = true
126126 tags = merge (var. tags , local. cluster_required_tags )
127127 metadata_options = var. metadata_options
128128 ignore_ami_changes = true
@@ -151,8 +151,8 @@ module "talos_worker_group" {
151151 name = " ${ var . cluster_name } -worker-group-${ each . value . name } -${ trimprefix (each. key , " ${ each . value . name } ." )} "
152152 ami = data. aws_ami . talos . id
153153 instance_type = each. value . instance_type
154- subnet_id = var . use_private_ips_only ? element (data . aws_subnets . private . ids , tonumber ( trimprefix (each . key , " ${ each . value . name } . " ))) : element (data. aws_subnets . public . ids , tonumber (trimprefix (each. key , " ${ each . value . name } ." )))
155- associate_public_ip_address = ! var . use_private_ips_only
154+ subnet_id = element (data. aws_subnets . public . ids , tonumber (trimprefix (each. key , " ${ each . value . name } ." )))
155+ associate_public_ip_address = true
156156 tags = merge (each. value . tags , var. tags , local. cluster_required_tags )
157157 metadata_options = var. metadata_options
158158 ignore_ami_changes = true
@@ -178,7 +178,7 @@ resource "talos_machine_secrets" "this" {
178178
179179data "talos_machine_configuration" "controlplane" {
180180 cluster_name = var. cluster_name
181- cluster_endpoint = " https://${ module . elb_k8s_elb . elb_dns_name } "
181+ cluster_endpoint = " https://${ aws_lb . api . dns_name } "
182182 machine_type = " controlplane"
183183 machine_secrets = talos_machine_secrets. this . machine_secrets
184184 kubernetes_version = var. kubernetes_version
@@ -191,11 +191,27 @@ data "talos_machine_configuration" "controlplane" {
191191 )
192192}
193193
194+ resource "talos_machine_configuration_apply" "controlplane" {
195+ for_each = { for index , instance in module . talos_control_plane_nodes : index => instance }
196+ client_configuration = talos_machine_secrets. this . client_configuration
197+ machine_configuration_input = data. talos_machine_configuration . controlplane . machine_configuration
198+ endpoint = module. talos_control_plane_nodes [each . key ]. public_ip
199+ node = module. talos_control_plane_nodes [each . key ]. private_ip
200+ }
201+
202+ resource "talos_machine_bootstrap" "this" {
203+ depends_on = [talos_machine_configuration_apply . controlplane ]
204+
205+ client_configuration = talos_machine_secrets. this . client_configuration
206+ endpoint = module. talos_control_plane_nodes . 0 . public_ip
207+ node = module. talos_control_plane_nodes . 0 . private_ip
208+ }
209+
194210data "talos_machine_configuration" "worker_group" {
195211 for_each = merge ([for info in var . worker_groups : { for index in range (0 , var. workers_count ) : " ${ info . name } .${ index } " => info }]... )
196212
197213 cluster_name = var. cluster_name
198- cluster_endpoint = " https://${ module . elb_k8s_elb . elb_dns_name } "
214+ cluster_endpoint = " https://${ aws_lb . api . dns_name } "
199215 machine_type = " worker"
200216 machine_secrets = talos_machine_secrets. this . machine_secrets
201217 kubernetes_version = var. kubernetes_version
@@ -208,44 +224,20 @@ data "talos_machine_configuration" "worker_group" {
208224 )
209225}
210226
211- resource "talos_machine_configuration_apply" "controlplane" {
212- for_each = { for index , instance in module . talos_control_plane_nodes : index => instance }
213- client_configuration = talos_machine_secrets. this . client_configuration
214- machine_configuration_input = data. talos_machine_configuration . controlplane . machine_configuration
215- endpoint = module. elb_k8s_elb . elb_dns_name
216- node = var. use_private_ips_only ? module. talos_control_plane_nodes [each . key ]. private_ip : module. talos_control_plane_nodes [each . key ]. public_ip
217- }
218-
219- # Wait until Talos APID has rotated its cert & ELB sees the node healthy
220- resource "time_sleep" "wait_api_ready" {
221- depends_on = [talos_machine_bootstrap . this ]
222- create_duration = " 30s"
223- }
224-
225227resource "talos_machine_configuration_apply" "worker_group" {
226- depends_on = [time_sleep . wait_api_ready ]
227-
228228 for_each = merge ([for info in var . worker_groups : { for index in range (0 , var. workers_count ) : " ${ info . name } .${ index } " => info }]... )
229229
230230 client_configuration = talos_machine_secrets. this . client_configuration
231231 machine_configuration_input = data. talos_machine_configuration . worker_group [each . key ]. machine_configuration
232- endpoint = module. elb_k8s_elb . elb_dns_name
233- node = var. use_private_ips_only ? module. talos_worker_group [each . key ]. private_ip : module. talos_worker_group [each . key ]. public_ip
234- }
235-
236- resource "talos_machine_bootstrap" "this" {
237- depends_on = [talos_machine_configuration_apply . controlplane ]
238-
239- client_configuration = talos_machine_secrets. this . client_configuration
240- endpoint = module. elb_k8s_elb . elb_dns_name
241- node = var. use_private_ips_only ? module. talos_control_plane_nodes . 0 . private_ip : module. talos_control_plane_nodes . 0 . public_ip
232+ endpoint = module. talos_worker_group [each . key ]. public_ip
233+ node = module. talos_worker_group [each . key ]. private_ip
242234}
243235
244236data "talos_client_configuration" "this" {
245237 cluster_name = var. cluster_name
246238 client_configuration = talos_machine_secrets. this . client_configuration
247- endpoints = [module . elb_k8s_elb . elb_dns_name ]
248- nodes = var . use_private_ips_only ? module. talos_control_plane_nodes . * . private_ip : module. talos_control_plane_nodes . * . public_ip
239+ endpoints = [aws_lb . api . dns_name ]
240+ nodes = flatten ([ module . talos_control_plane_nodes . * . private_ip , flatten ([ for node in module . talos_worker_group : node . private_ip ])])
249241}
250242
251243resource "local_file" "talosconfig" {
@@ -257,8 +249,8 @@ resource "talos_cluster_kubeconfig" "this" {
257249 depends_on = [talos_machine_bootstrap . this ]
258250
259251 client_configuration = talos_machine_secrets. this . client_configuration
260- endpoint = module. elb_k8s_elb . elb_dns_name
261- node = var . use_private_ips_only ? module. talos_control_plane_nodes . 0 . private_ip : module . talos_control_plane_nodes . 0 . public_ip
252+ endpoint = module. talos_control_plane_nodes . 0 . public_ip
253+ node = module. talos_control_plane_nodes . 0 . private_ip
262254}
263255
264256resource "local_file" "kubeconfig" {
0 commit comments