Skip to content

Commit df84c5c

Browse files
Updated reservation_definitions.tf for more precise cpu validation
1 parent 1d42a4d commit df84c5c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

modules/compute/gke-node-pool/reservation_definitions.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ locals {
5757

5858
# Build two maps to be used to compare the VM properties between reservations and the node pool
5959
# Skip this for TPUs
60-
reservation_vm_properties = local.has_gpu ? ([for reservation in local.verified_specific_reservations : {
60+
# Validation of only machine-type for CPUs and and both machine-type and guest-accelerators for GPUs
61+
reservation_vm_properties = [for reservation in local.verified_specific_reservations : {
6162
"machine_type" : try(reservation.specific_reservation[0].instance_properties[0].machine_type, "")
62-
"guest_accelerators" : { for acc in try(reservation.specific_reservation[0].instance_properties[0].guest_accelerators, []) : acc.accelerator_type => acc.accelerator_count }
63-
}]) : []
63+
"guest_accelerators" : local.has_gpu ? ( # Conditional check for GPUs
64+
{ for acc in try(reservation.specific_reservation[0].instance_properties[0].guest_accelerators, []) : acc.accelerator_type => acc.accelerator_count }
65+
) : {} # If no GPUs, it's an empty map {}
66+
}]
67+
6468
nodepool_vm_properties = {
6569
"machine_type" : var.machine_type
66-
"guest_accelerators" : { for acc in try(local.guest_accelerator, []) : coalesce(acc.type, try(local.generated_guest_accelerator[0].type, "")) => coalesce(acc.count, try(local.generated_guest_accelerator[0].count, 0)) }
70+
"guest_accelerators" : local.has_gpu ? ( # Conditional check for GPUs
71+
{ for acc in try(local.guest_accelerator, []) : coalesce(acc.type, try(local.generated_guest_accelerator[0].type, "")) => coalesce(acc.count, try(local.generated_guest_accelerator[0].count, 0)) }
72+
) : {} # If no GPUs, it's an empty map {}
6773
}
6874

6975
# Compare two maps by counting the keys that mismatch.

0 commit comments

Comments
 (0)