Last active
June 24, 2023 04:17
-
-
Save coryodaniel/ba99b2877caed9ef5525fa5e436e96c4 to your computer and use it in GitHub Desktop.
Optional dynamic blocks in terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "gpu" { | |
description = "Enable and configure node GPUs" | |
type = object({ | |
type = string | |
count = number | |
}) | |
default = null | |
# or... | |
default = { | |
type = "nvidia-tesla-k80" | |
count = 1 | |
} | |
} | |
resource "google_container_node_pool" "gpu-pool" { | |
name = "gpu-pool" | |
location = "us-central1-a" | |
cluster = "kewl-cluster" | |
initial_node_count = 0 | |
autoscaling { | |
min_node_count = 0 | |
max_node_count = 10 | |
} | |
node_config { | |
machine_type = "n1-standard-8" | |
dynamic "guest_accelerator" { | |
# The '*' notation here is a quirk. | |
# For non-list objects it will wrap the item in a list, for null it returns an empty list | |
for_each = var.gpu[*] | |
content { | |
type = guest_accelerator.value.type | |
count = guest_accelerator.value.count | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment