Skip to content

Commit 4f21330

Browse files
authored
feat: Add advanced machine feature options for enabling virtualization and setting threads per core (#236)
1 parent 000323c commit 4f21330

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

examples/instance_template/simple/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ This is a simple, minimal example of how to use the instance_template module.
77

88
| Name | Description | Type | Default | Required |
99
|------|-------------|------|---------|:--------:|
10+
| enable\_nested\_virtualization | Defines whether the instance should have nested virtualization enabled. | `bool` | `false` | no |
1011
| labels | Labels, provided as a map | `map(string)` | n/a | yes |
1112
| project\_id | The GCP project to use for integration tests | `string` | n/a | yes |
1213
| region | The GCP region to create and test resources in | `string` | `"us-central1"` | no |
1314
| service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account. | <pre>object({<br> email = string<br> scopes = set(string)<br> })</pre> | `null` | no |
1415
| subnetwork | The name of the subnetwork create this instance in. | `string` | `""` | no |
1516
| tags | Network tags, provided as a list | `list(string)` | n/a | yes |
17+
| threads\_per\_core | The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. | `string` | `null` | no |
1618

1719
## Outputs
1820

examples/instance_template/simple/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ locals {
3232
}
3333

3434
module "instance_template" {
35-
source = "../../../modules/instance_template"
36-
project_id = var.project_id
37-
subnetwork = var.subnetwork
38-
service_account = var.service_account
39-
name_prefix = "simple"
40-
tags = var.tags
41-
labels = var.labels
42-
access_config = [local.access_config]
35+
source = "../../../modules/instance_template"
36+
project_id = var.project_id
37+
subnetwork = var.subnetwork
38+
service_account = var.service_account
39+
name_prefix = "simple"
40+
tags = var.tags
41+
labels = var.labels
42+
access_config = [local.access_config]
43+
enable_nested_virtualization = var.enable_nested_virtualization
44+
threads_per_core = var.threads_per_core
4345
}

examples/instance_template/simple/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ variable "labels" {
5151
description = "Labels, provided as a map"
5252
}
5353

54+
variable "enable_nested_virtualization" {
55+
type = bool
56+
description = "Defines whether the instance should have nested virtualization enabled."
57+
default = false
58+
}
59+
60+
variable "threads_per_core" {
61+
type = string
62+
description = "The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1."
63+
default = null
64+
}

modules/instance_template/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
2424
| disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no |
2525
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no |
2626
| 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 |
27+
| enable\_nested\_virtualization | Defines whether the instance should have nested virtualization enabled. | `bool` | `false` | no |
2728
| 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 |
2829
| 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 |
2930
| labels | Labels, provided as a map | `map(string)` | `{}` | no |
@@ -46,6 +47,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
4647
| subnetwork | The name of the subnetwork to attach this interface to. The subnetwork must exist in the same region this instance will be created in. Either network or subnetwork must be provided. | `string` | `""` | no |
4748
| subnetwork\_project | The ID of the project in which the subnetwork belongs. If it is not provided, the provider project is used. | `string` | `""` | no |
4849
| tags | Network tags, provided as a list | `list(string)` | `[]` | no |
50+
| threads\_per\_core | The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. | `any` | `null` | no |
4951

5052
## Outputs
5153

modules/instance_template/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ resource "google_compute_instance_template" "tpl" {
148148
on_host_maintenance = local.on_host_maintenance
149149
}
150150

151+
advanced_machine_features {
152+
enable_nested_virtualization = var.enable_nested_virtualization
153+
threads_per_core = var.threads_per_core
154+
}
155+
151156
dynamic "shielded_instance_config" {
152157
for_each = local.shielded_vm_configs
153158
content {

modules/instance_template/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ variable "region" {
7171
default = null
7272
}
7373

74+
variable "enable_nested_virtualization" {
75+
type = bool
76+
description = "Defines whether the instance should have nested virtualization enabled."
77+
default = false
78+
}
79+
80+
variable "threads_per_core" {
81+
description = "The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1."
82+
default = null
83+
}
84+
7485
#######
7586
# disk
7687
#######

0 commit comments

Comments
 (0)