Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Last active June 24, 2023 04:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryodaniel/ba99b2877caed9ef5525fa5e436e96c4 to your computer and use it in GitHub Desktop.
Save coryodaniel/ba99b2877caed9ef5525fa5e436e96c4 to your computer and use it in GitHub Desktop.
Optional dynamic blocks in terraform
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