Skip to content

Commit 81d5235

Browse files
authored
compute: added support for advanced_machine_features.turbo_mode (#12148)
1 parent be84776 commit 81d5235

10 files changed

+64
-27
lines changed

mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ func expandAdvancedMachineFeatures(d tpgresource.TerraformResourceData) *compute
662662
return &compute.AdvancedMachineFeatures{
663663
EnableNestedVirtualization: d.Get(prefix + ".enable_nested_virtualization").(bool),
664664
ThreadsPerCore: int64(d.Get(prefix + ".threads_per_core").(int)),
665+
TurboMode: d.Get(prefix + ".turbo_mode").(string),
665666
VisibleCoreCount: int64(d.Get(prefix + ".visible_core_count").(int)),
666667
}
667668
}
@@ -673,6 +674,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac
673674
return []map[string]interface{}{{"{{"}}
674675
"enable_nested_virtualization": AdvancedMachineFeatures.EnableNestedVirtualization,
675676
"threads_per_core": AdvancedMachineFeatures.ThreadsPerCore,
677+
"turbo_mode": AdvancedMachineFeatures.TurboMode,
676678
"visible_core_count": AdvancedMachineFeatures.VisibleCoreCount,
677679
{{"}}"}}
678680
}

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

+17-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func IpCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
5454
}
5555

5656
var (
57+
advancedMachineFeaturesKeys = []string{
58+
"advanced_machine_features.0.enable_nested_virtualization",
59+
"advanced_machine_features.0.threads_per_core",
60+
"advanced_machine_features.0.turbo_mode",
61+
"advanced_machine_features.0.visible_core_count",
62+
}
63+
5764
bootDiskKeys = []string{
5865
"boot_disk.0.auto_delete",
5966
"boot_disk.0.device_name",
@@ -1091,19 +1098,26 @@ be from 0 to 999,999,999 inclusive.`,
10911098
"enable_nested_virtualization": {
10921099
Type: schema.TypeBool,
10931100
Optional: true,
1094-
AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core"},
1101+
AtLeastOneOf: advancedMachineFeaturesKeys,
10951102
Description: `Whether to enable nested virtualization or not.`,
10961103
},
10971104
"threads_per_core": {
10981105
Type: schema.TypeInt,
10991106
Optional: true,
1100-
AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core"},
1107+
AtLeastOneOf: advancedMachineFeaturesKeys,
11011108
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
11021109
},
1110+
"turbo_mode": {
1111+
Type: schema.TypeString,
1112+
Optional: true,
1113+
AtLeastOneOf: advancedMachineFeaturesKeys,
1114+
Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`,
1115+
ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false),
1116+
},
11031117
"visible_core_count": {
11041118
Type: schema.TypeInt,
11051119
Optional: true,
1106-
AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core","advanced_machine_features.0.visible_core_count"},
1120+
AtLeastOneOf: advancedMachineFeaturesKeys,
11071121
Description: `The number of physical cores to expose to an instance. Multiply by the number of threads per core to compute the total number of virtual CPUs to expose to the instance. If unset, the number of cores is inferred from the instance\'s nominal CPU count and the underlying platform\'s SMT width.`,
11081122
},
11091123
},

mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,12 @@ be from 0 to 999,999,999 inclusive.`,
964964
ForceNew: true,
965965
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
966966
},
967+
"turbo_mode": {
968+
Type: schema.TypeString,
969+
Optional: true,
970+
Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`,
971+
ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false),
972+
},
967973
"visible_core_count": {
968974
Type: schema.TypeInt,
969975
Optional: true,

mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl

+7-6
Original file line numberDiff line numberDiff line change
@@ -3757,11 +3757,11 @@ data "google_compute_image" "my_image" {
37573757

37583758
resource "google_compute_instance_template" "foobar" {
37593759
name = "tf-test-instance-template-%s"
3760-
machine_type = "n2-standard-2" // Nested Virt isn't supported on E2 and N2Ds https://cloud.google.com/compute/docs/instances/nested-virtualization/overview#restrictions and https://cloud.google.com/compute/docs/instances/disabling-smt#limitations
3760+
machine_type = "c4-standard-2"
37613761

37623762
disk {
37633763
source_image = data.google_compute_image.my_image.self_link
3764-
auto_delete = true
3764+
auto_delete = true
37653765
boot = true
37663766
}
37673767

@@ -3770,13 +3770,14 @@ resource "google_compute_instance_template" "foobar" {
37703770
}
37713771

37723772
advanced_machine_features {
3773-
threads_per_core = 1
3774-
enable_nested_virtualization = true
3775-
visible_core_count = 1
3773+
enable_nested_virtualization = true
3774+
threads_per_core = 1
3775+
turbo_mode = "ALL_CORE_MAX"
3776+
visible_core_count = 1
37763777
}
37773778

37783779
scheduling {
3779-
on_host_maintenance = "TERMINATE"
3780+
on_host_maintenance = "TERMINATE"
37803781
}
37813782

37823783
}

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -7158,7 +7158,7 @@ data "google_compute_image" "my_image" {
71587158

71597159
resource "google_compute_instance" "foobar" {
71607160
name = "%s"
7161-
machine_type = "n1-standard-2" // Nested Virt isn't supported on E2 and N2Ds https://cloud.google.com/compute/docs/instances/nested-virtualization/overview#restrictions and https://cloud.google.com/compute/docs/instances/disabling-smt#limitations
7161+
machine_type = "c4-standard-2"
71627162
zone = "us-central1-a"
71637163

71647164
boot_disk {
@@ -7186,7 +7186,7 @@ data "google_compute_image" "my_image" {
71867186

71877187
resource "google_compute_instance" "foobar" {
71887188
name = "%s"
7189-
machine_type = "n1-standard-2" // Nested Virt isn't supported on E2 and N2Ds https://cloud.google.com/compute/docs/instances/nested-virtualization/overview#restrictions and https://cloud.google.com/compute/docs/instances/disabling-smt#limitations
7189+
machine_type = "c4-standard-2"
71907190
zone = "us-central1-a"
71917191

71927192
boot_disk {
@@ -7199,9 +7199,10 @@ resource "google_compute_instance" "foobar" {
71997199
network = "default"
72007200
}
72017201
advanced_machine_features {
7202-
threads_per_core = 1
7203-
enable_nested_virtualization = true
7204-
visible_core_count = 1
7202+
enable_nested_virtualization = true
7203+
threads_per_core = 1
7204+
turbo_mode = "ALL_CORE_MAX"
7205+
visible_core_count = 1
72057206
}
72067207
allow_stopping_for_update = true
72077208
}

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ be from 0 to 999,999,999 inclusive.`,
916916
ForceNew: true,
917917
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
918918
},
919+
"turbo_mode": {
920+
Type: schema.TypeString,
921+
Optional: true,
922+
Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`,
923+
ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false),
924+
},
919925
"visible_core_count": {
920926
Type: schema.TypeInt,
921927
Optional: true,

mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl

+5-4
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,8 @@ data "google_compute_image" "my_image" {
31423142

31433143
resource "google_compute_region_instance_template" "foobar" {
31443144
name = "tf-test-instance-template-%s"
3145-
region = "us-central1"
3146-
machine_type = "n2-standard-2" // Nested Virt isn't supported on E2 and N2Ds https://cloud.google.com/compute/docs/instances/nested-virtualization/overview#restrictions and https://cloud.google.com/compute/docs/instances/disabling-smt#limitations
3145+
region = "us-central1"
3146+
machine_type = "c2-standard-2"
31473147

31483148
disk {
31493149
source_image = data.google_compute_image.my_image.self_link
@@ -3156,9 +3156,10 @@ resource "google_compute_region_instance_template" "foobar" {
31563156
}
31573157

31583158
advanced_machine_features {
3159-
threads_per_core = 1
31603159
enable_nested_virtualization = true
3161-
visible_core_count = 1
3160+
threads_per_core = 1
3161+
turbo_mode = "ALL_CORE_MAX"
3162+
visible_core_count = 1
31623163
}
31633164

31643165
scheduling {

mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown

+5-3
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,13 @@ specified, then this instance will have no external IPv6 Internet access. Struct
566566

567567
<a name="nested_advanced_machine_features"></a>The `advanced_machine_features` block supports:
568568

569-
* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
569+
* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
570570

571-
* `threads_per_core` (Optional) he number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
571+
* `threads_per_core` - (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
572572

573-
* `visible_core_count` (Optional) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
573+
* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default).
574+
575+
* `visible_core_count` - (Optional) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
574576

575577
<a name="nested_reservation_affinity"></a>The `reservation_affinity` block supports:
576578

mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown

+5-3
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,13 @@ The `specific_reservation` block supports:
722722

723723
<a name="nested_advanced_machine_features"></a>The `advanced_machine_features` block supports:
724724

725-
* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
725+
* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
726726

727-
* `threads_per_core` (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
727+
* `threads_per_core` - (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
728728

729-
* `visible_core_count` (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
729+
* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default).
730+
731+
* `visible_core_count` - (Optional) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
730732

731733
## Attributes Reference
732734

mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown

+5-3
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,13 @@ The `specific_reservation` block supports:
682682

683683
<a name="nested_advanced_machine_features"></a>The `advanced_machine_features` block supports:
684684

685-
* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
685+
* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.
686686

687-
* `threads_per_core` (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
687+
* `threads_per_core` - (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
688688

689-
* `visible_core_count` (Optional, ) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
689+
* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default).
690+
691+
* `visible_core_count` - (Optional) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).
690692

691693
## Attributes Reference
692694

0 commit comments

Comments
 (0)