@@ -274,22 +274,22 @@ locals {
274274# resources where "ForceNew" is "true". schemaNodeConfig can be found in node_config.go at
275275# https://github.com/terraform-providers/terraform-provider-google/blob/master/google/node_config.go#L22
276276resource "random_id" "name" {
277- count = length(var .node_pools)
277+ for_each = local .node_pools
278278 byte_length = 2
279- prefix = format("%s-", lookup(var.node_pools[count.index] , "name"))
279+ prefix = format("%s-", lookup(each.value , "name"))
280280 keepers = merge(
281281 zipmap(
282282 local.force_node_pool_recreation_resources,
283- [for keeper in local.force_node_pool_recreation_resources : lookup(var.node_pools[count.index] , keeper, "")]
283+ [for keeper in local.force_node_pool_recreation_resources : lookup(each.value , keeper, "")]
284284 ),
285285 {
286286 labels = join(",",
287287 sort(
288288 concat(
289289 keys(local.node_pools_labels["all"]),
290290 values(local.node_pools_labels["all"]),
291- keys(local.node_pools_labels[var.node_pools[count.index] ["name"]]),
292- values(local.node_pools_labels[var.node_pools[count.index] ["name"]])
291+ keys(local.node_pools_labels[each.value ["name"]]),
292+ values(local.node_pools_labels[each.value ["name"]])
293293 )
294294 )
295295 )
@@ -300,8 +300,8 @@ resource "random_id" "name" {
300300 concat(
301301 keys(local.node_pools_metadata["all"]),
302302 values(local.node_pools_metadata["all"]),
303- keys(local.node_pools_metadata[var.node_pools[count.index] ["name"]]),
304- values(local.node_pools_metadata[var.node_pools[count.index] ["name"]])
303+ keys(local.node_pools_metadata[each.value ["name"]]),
304+ values(local.node_pools_metadata[each.value ["name"]])
305305 )
306306 )
307307 )
@@ -311,7 +311,7 @@ resource "random_id" "name" {
311311 sort(
312312 concat(
313313 local.node_pools_oauth_scopes["all"],
314- local.node_pools_oauth_scopes[var.node_pools[count.index] ["name"]]
314+ local.node_pools_oauth_scopes[each.value ["name"]]
315315 )
316316 )
317317 )
@@ -321,7 +321,7 @@ resource "random_id" "name" {
321321 sort(
322322 concat(
323323 local.node_pools_tags["all"],
324- local.node_pools_tags[var.node_pools[count.index] ["name"]]
324+ local.node_pools_tags[each.value ["name"]]
325325 )
326326 )
327327 )
@@ -336,66 +336,66 @@ resource "google_container_node_pool" "pools" {
336336 {% else %}
337337 provider = google
338338 {% endif %}
339- count = length(var .node_pools)
339+ for_each = local .node_pools
340340 {% if update_variant %}
341- name = random_id.name.*.hex[count.index ]
341+ name = random_id.name.*.hex[each.key ]
342342 {% else %}
343- name = var.node_pools[count.index]["name"]
343+ name = each.key
344344 {% endif %}
345345 project = var.project_id
346346 location = local.location
347347 {% if beta_cluster %}
348348 // use node_locations if provided, defaults to cluster level node_locations if not specified
349- node_locations = lookup(var.node_pools[count.index] , "node_locations", "") != "" ? split(",", var.node_pools[count.index] ["node_locations"]) : null
349+ node_locations = lookup(each.value , "node_locations", "") != "" ? split(",", each.value ["node_locations"]) : null
350350 {% endif %}
351351
352352 cluster = google_container_cluster.primary.name
353353
354- version = lookup(var.node_pools[count.index] , "auto_upgrade", false) ? "" : lookup(
355- var.node_pools[count.index] ,
354+ version = lookup(each.value , "auto_upgrade", false) ? "" : lookup(
355+ each.value ,
356356 "version",
357357 local.node_version,
358358 )
359359
360- initial_node_count = lookup(var.node_pools[count.index] , "autoscaling", true) ? lookup(
361- var.node_pools[count.index] ,
360+ initial_node_count = lookup(each.value , "autoscaling", true) ? lookup(
361+ each.value ,
362362 "initial_node_count",
363- lookup(var.node_pools[count.index] , "min_count", 1)
363+ lookup(each.value , "min_count", 1)
364364 ) : null
365365
366366 {% if beta_cluster %}
367- max_pods_per_node = lookup(var.node_pools[count.index] , "max_pods_per_node", null)
367+ max_pods_per_node = lookup(each.value , "max_pods_per_node", null)
368368 {% endif %}
369369
370- node_count = lookup(var.node_pools[count.index] , "autoscaling", true) ? null : lookup(var.node_pools[count.index] , "node_count", 1)
370+ node_count = lookup(each.value , "autoscaling", true) ? null : lookup(each.value , "node_count", 1)
371371
372372 dynamic "autoscaling" {
373- for_each = lookup(var.node_pools[count.index] , "autoscaling", true) ? [var.node_pools[count.index] ] : []
373+ for_each = lookup(each.value , "autoscaling", true) ? [each.value ] : []
374374 content {
375375 min_node_count = lookup(autoscaling.value, "min_count", 1)
376376 max_node_count = lookup(autoscaling.value, "max_count", 100)
377377 }
378378 }
379379
380380 management {
381- auto_repair = lookup(var.node_pools[count.index] , "auto_repair", true)
382- auto_upgrade = lookup(var.node_pools[count.index] , "auto_upgrade", local.default_auto_upgrade)
381+ auto_repair = lookup(each.value , "auto_repair", true)
382+ auto_upgrade = lookup(each.value , "auto_upgrade", local.default_auto_upgrade)
383383 }
384384
385385 node_config {
386- image_type = lookup(var.node_pools[count.index] , "image_type", "COS")
387- machine_type = lookup(var.node_pools[count.index] , "machine_type", "n1-standard-2")
386+ image_type = lookup(each.value , "image_type", "COS")
387+ machine_type = lookup(each.value , "machine_type", "n1-standard-2")
388388 labels = merge(
389389 lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
390- lookup(lookup(local.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index] ["name"] } : {},
390+ lookup(lookup(local.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value ["name"] } : {},
391391 local.node_pools_labels["all"],
392- local.node_pools_labels[var.node_pools[count.index] ["name"]],
392+ local.node_pools_labels[each.value ["name"]],
393393 )
394394 metadata = merge(
395395 lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
396- lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index] ["name"] } : {},
396+ lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value ["name"] } : {},
397397 local.node_pools_metadata["all"],
398- local.node_pools_metadata[var.node_pools[count.index] ["name"]],
398+ local.node_pools_metadata[each.value ["name"]],
399399 {
400400 "disable-legacy-endpoints" = var.disable_legacy_metadata_endpoints
401401 },
@@ -404,7 +404,7 @@ resource "google_container_node_pool" "pools" {
404404 dynamic "taint" {
405405 for_each = concat(
406406 local.node_pools_taints["all"],
407- local.node_pools_taints[var.node_pools[count.index] ["name"]],
407+ local.node_pools_taints[each.value ["name"]],
408408 )
409409 content {
410410 effect = taint.value.effect
@@ -415,31 +415,31 @@ resource "google_container_node_pool" "pools" {
415415 {% endif %}
416416 tags = concat(
417417 lookup(local.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [],
418- lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index] ["name"]}"] : [],
418+ lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${each.value ["name"]}"] : [],
419419 local.node_pools_tags["all"],
420- local.node_pools_tags[var.node_pools[count.index] ["name"]],
420+ local.node_pools_tags[each.value ["name"]],
421421 )
422422
423- local_ssd_count = lookup(var.node_pools[count.index] , "local_ssd_count", 0)
424- disk_size_gb = lookup(var.node_pools[count.index] , "disk_size_gb", 100)
425- disk_type = lookup(var.node_pools[count.index] , "disk_type", "pd-standard")
423+ local_ssd_count = lookup(each.value , "local_ssd_count", 0)
424+ disk_size_gb = lookup(each.value , "disk_size_gb", 100)
425+ disk_type = lookup(each.value , "disk_type", "pd-standard")
426426
427427 service_account = lookup(
428- var.node_pools[count.index] ,
428+ each.value ,
429429 "service_account",
430430 local.service_account,
431431 )
432- preemptible = lookup(var.node_pools[count.index] , "preemptible", false)
432+ preemptible = lookup(each.value , "preemptible", false)
433433
434434 oauth_scopes = concat(
435435 local.node_pools_oauth_scopes["all"],
436- local.node_pools_oauth_scopes[var.node_pools[count.index] ["name"]],
436+ local.node_pools_oauth_scopes[each.value ["name"]],
437437 )
438438
439439 guest_accelerator = [
440- for guest_accelerator in lookup(var.node_pools[count.index] , "accelerator_count", 0) > 0 ? [{
441- type = lookup(var.node_pools[count.index] , "accelerator_type", "")
442- count = lookup(var.node_pools[count.index] , "accelerator_count", 0)
440+ for guest_accelerator in lookup(each.value , "accelerator_count", 0) > 0 ? [{
441+ type = lookup(each.value , "accelerator_type", "")
442+ count = lookup(each.value , "accelerator_count", 0)
443443 }] : [] : {
444444 type = guest_accelerator["type"]
445445 count = guest_accelerator["count"]
@@ -451,7 +451,7 @@ resource "google_container_node_pool" "pools" {
451451 for_each = local.cluster_node_metadata_config
452452
453453 content {
454- node_metadata = lookup(var.node_pools[count.index] , "node_metadata", workload_metadata_config.value.node_metadata)
454+ node_metadata = lookup(each.value , "node_metadata", workload_metadata_config.value.node_metadata)
455455 }
456456 }
457457
0 commit comments