Skip to content

Commit

Permalink
feat: Add support for guest_accelerator for the instance_template mod…
Browse files Browse the repository at this point in the history
…ule (#160)

* Add GPU variable tp the inputs

* Add description to the GPU variable

* Revert README changes

* Generate docs with make generate_docs

* Fix issue with default guest_accelerator setting

* Remove deprecated list() notation in favor of []
  • Loading branch information
Shabirmean authored Apr 13, 2021
1 parent 49829e8 commit a535e13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no |
| enable\_confidential\_vm | Whether to enable the Confidential VM configuration on the instance. Note that the instance image must support Confidential VMs. See https://cloud.google.com/compute/docs/images | `bool` | `false` | no |
| enable\_shielded\_vm | Whether to enable the Shielded VM configuration on the instance. Note that the instance image must support Shielded VMs. See https://cloud.google.com/compute/docs/images | `bool` | `false` | no |
| gpu | GPU information. Type and count of GPU to attach to the instance template. See https://cloud.google.com/compute/docs/gpus more details | <pre>object({<br> type = string<br> count = number<br> })</pre> | `null` | no |
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
| machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no |
| metadata | Metadata, provided as a map | `map(string)` | `{}` | no |
Expand Down
11 changes: 10 additions & 1 deletion modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ locals {
shielded_vm_configs = var.enable_shielded_vm ? [true] : []
confidential_instance_config = var.enable_confidential_vm ? [true] : []

gpu_enabled = var.gpu != null
on_host_maintenance = (
var.preemptible || var.enable_confidential_vm
var.preemptible || var.enable_confidential_vm || local.gpu_enabled
? "TERMINATE"
: var.on_host_maintenance
)
Expand Down Expand Up @@ -141,4 +142,12 @@ resource "google_compute_instance_template" "tpl" {
confidential_instance_config {
enable_confidential_compute = var.enable_confidential_vm
}

dynamic "guest_accelerator" {
for_each = local.gpu_enabled ? [var.gpu] : []
content {
type = guest_accelerator.value.type
count = guest_accelerator.value.count
}
}
}
12 changes: 12 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,15 @@ variable "access_config" {
}))
default = []
}

###########################
# Guest Accelerator (GPU)
###########################
variable "gpu" {
description = "GPU information. Type and count of GPU to attach to the instance template. See https://cloud.google.com/compute/docs/gpus more details"
type = object({
type = string
count = number
})
default = null
}

0 comments on commit a535e13

Please sign in to comment.