@@ -386,10 +386,22 @@ locals {
386386 supported_machine_types_for_install_dependencies = [" a3-highgpu-8g" , " a3-megagpu-8g" ]
387387}
388388
389+ # Replicates GKE's naming logic for its instance templates. The full
390+ # pattern is "gke-{cluster_name}-{nodepool_name}-{hash}".
391+ #
392+ # This code builds the "{cluster_name}-{nodepool_name}" prefix, which is
393+ # capped at 32 characters plus a dash '-' in between, by truncating names if needed:
394+ # - If both names > 16 chars, both are cut to 16.
395+ # - If one name > 16, it's shortened so the combined name length is 32.
389396data "google_compute_region_instance_template" "instance_template" {
390- for_each = { for idx , np in google_container_node_pool . node_pool : idx => np }
391- project = var. project_id
392- filter = " name : ${ substr (" gke-${ local . cluster_name } -${ each . value . name } " , 0 , 37 )} *"
397+ for_each = { for idx , np in google_container_node_pool . node_pool : idx => np }
398+ project = var. project_id
399+ filter = " name: gke-${
400+ (length (local. cluster_name ) <= 16 && length (each. value . name ) <= 16 ) ? " ${ local . cluster_name } -${ each . value . name } " :
401+ (length (local. cluster_name ) > 16 && length (each. value . name ) > 16 ) ? " ${ substr (local. cluster_name , 0 , 16 )} -${ substr (each. value . name , 0 , 16 )} " :
402+ (length (local. cluster_name ) > 16 ) ? " ${ substr (local. cluster_name , 0 , 32 - length (each. value . name ))} -${ each . value . name } " :
403+ " ${ local . cluster_name } -${ substr (each. value . name , 0 , 32 - length (local. cluster_name ))} "
404+ } *"
393405 most_recent = true
394406}
395407
0 commit comments