From 340fd345eb3f187deeec22f7e4824d02da742f9b Mon Sep 17 00:00:00 2001 From: William Yardley Date: Fri, 25 Oct 2024 20:33:20 -0700 Subject: [PATCH] compute: added support for `advanced_machine_features.turbo_mode` - Added support for `advanced_machine_features.turbo_mode` to `google_compute_instance`, `google_compute_instance_template`, and `google_compute_region_instance_template` - Adjusted tests to use c4 instance types for `advanced_machine_features` tests - Minor docs and formatting fixes Fixes hashicorp/terraform-provider-google#20023 --- .../compute/compute_instance_helpers.go.tmpl | 2 ++ .../compute/resource_compute_instance.go.tmpl | 20 ++++++++++++++++--- ...resource_compute_instance_template.go.tmpl | 6 ++++++ ...rce_compute_instance_template_test.go.tmpl | 13 ++++++------ .../resource_compute_instance_test.go.tmpl | 11 +++++----- ...e_compute_region_instance_template.go.tmpl | 6 ++++++ ...pute_region_instance_template_test.go.tmpl | 9 +++++---- .../docs/r/compute_instance.html.markdown | 8 +++++--- .../r/compute_instance_template.html.markdown | 8 +++++--- ...ute_region_instance_template.html.markdown | 8 +++++--- 10 files changed, 64 insertions(+), 27 deletions(-) diff --git a/mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl b/mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl index d7e1f1a52f8f..ecb1f5cc3c5f 100644 --- a/mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl @@ -662,6 +662,7 @@ func expandAdvancedMachineFeatures(d tpgresource.TerraformResourceData) *compute return &compute.AdvancedMachineFeatures{ EnableNestedVirtualization: d.Get(prefix + ".enable_nested_virtualization").(bool), ThreadsPerCore: int64(d.Get(prefix + ".threads_per_core").(int)), + TurboMode: d.Get(prefix + ".turbo_mode").(string), VisibleCoreCount: int64(d.Get(prefix + ".visible_core_count").(int)), } } @@ -673,6 +674,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac return []map[string]interface{}{{"{{"}} "enable_nested_virtualization": AdvancedMachineFeatures.EnableNestedVirtualization, "threads_per_core": AdvancedMachineFeatures.ThreadsPerCore, + "turbo_mode": AdvancedMachineFeatures.TurboMode, "visible_core_count": AdvancedMachineFeatures.VisibleCoreCount, {{"}}"}} } diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl index 3b1ff46a2250..c0bea3818dc7 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl @@ -54,6 +54,13 @@ func IpCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { } var ( + advancedMachineFeaturesKeys = []string{ + "advanced_machine_features.0.enable_nested_virtualization", + "advanced_machine_features.0.threads_per_core", + "advanced_machine_features.0.turbo_mode", + "advanced_machine_features.0.visible_core_count", + } + bootDiskKeys = []string{ "boot_disk.0.auto_delete", "boot_disk.0.device_name", @@ -1091,19 +1098,26 @@ be from 0 to 999,999,999 inclusive.`, "enable_nested_virtualization": { Type: schema.TypeBool, Optional: true, - AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core"}, + AtLeastOneOf: advancedMachineFeaturesKeys, Description: `Whether to enable nested virtualization or not.`, }, "threads_per_core": { Type: schema.TypeInt, Optional: true, - AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core"}, + AtLeastOneOf: advancedMachineFeaturesKeys, 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.`, }, + "turbo_mode": { + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: advancedMachineFeaturesKeys, + Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`, + ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false), + }, "visible_core_count": { Type: schema.TypeInt, Optional: true, - AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization","advanced_machine_features.0.threads_per_core","advanced_machine_features.0.visible_core_count"}, + AtLeastOneOf: advancedMachineFeaturesKeys, 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.`, }, }, diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl index 43a2063de52e..d5af5e60f92c 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl @@ -964,6 +964,12 @@ be from 0 to 999,999,999 inclusive.`, ForceNew: true, 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.`, }, + "turbo_mode": { + Type: schema.TypeString, + Optional: true, + Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`, + ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false), + }, "visible_core_count": { Type: schema.TypeInt, Optional: true, diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl index 905dde01495b..b8e404ff4f9c 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_test.go.tmpl @@ -3757,11 +3757,11 @@ data "google_compute_image" "my_image" { resource "google_compute_instance_template" "foobar" { name = "tf-test-instance-template-%s" - 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 + machine_type = "c4-standard-2" disk { source_image = data.google_compute_image.my_image.self_link - auto_delete = true + auto_delete = true boot = true } @@ -3770,13 +3770,14 @@ resource "google_compute_instance_template" "foobar" { } advanced_machine_features { - threads_per_core = 1 - enable_nested_virtualization = true - visible_core_count = 1 + enable_nested_virtualization = true + threads_per_core = 1 + turbo_mode = "ALL_CORE_MAX" + visible_core_count = 1 } scheduling { - on_host_maintenance = "TERMINATE" + on_host_maintenance = "TERMINATE" } } diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl index 640450bc7915..d205e7753f27 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl @@ -7158,7 +7158,7 @@ data "google_compute_image" "my_image" { resource "google_compute_instance" "foobar" { name = "%s" - 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 + machine_type = "c4-standard-2" zone = "us-central1-a" boot_disk { @@ -7186,7 +7186,7 @@ data "google_compute_image" "my_image" { resource "google_compute_instance" "foobar" { name = "%s" - 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 + machine_type = "c4-standard-2" zone = "us-central1-a" boot_disk { @@ -7199,9 +7199,10 @@ resource "google_compute_instance" "foobar" { network = "default" } advanced_machine_features { - threads_per_core = 1 - enable_nested_virtualization = true - visible_core_count = 1 + enable_nested_virtualization = true + threads_per_core = 1 + turbo_mode = "ALL_CORE_MAX" + visible_core_count = 1 } allow_stopping_for_update = true } diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl index b59f4c5f2a80..f3888bbd2431 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template.go.tmpl @@ -916,6 +916,12 @@ be from 0 to 999,999,999 inclusive.`, ForceNew: true, 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.`, }, + "turbo_mode": { + Type: schema.TypeString, + Optional: true, + Description: `Turbo frequency mode to use for the instance. Currently supported modes is "ALL_CORE_MAX".`, + ValidateFunc: validation.StringInSlice([]string{"ALL_CORE_MAX"}, false), + }, "visible_core_count": { Type: schema.TypeInt, Optional: true, diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl index f8cd2bd6c7d9..406297f8da06 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_test.go.tmpl @@ -3142,8 +3142,8 @@ data "google_compute_image" "my_image" { resource "google_compute_region_instance_template" "foobar" { name = "tf-test-instance-template-%s" - region = "us-central1" - 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 + region = "us-central1" + machine_type = "c2-standard-2" disk { source_image = data.google_compute_image.my_image.self_link @@ -3156,9 +3156,10 @@ resource "google_compute_region_instance_template" "foobar" { } advanced_machine_features { - threads_per_core = 1 enable_nested_virtualization = true - visible_core_count = 1 + threads_per_core = 1 + turbo_mode = "ALL_CORE_MAX" + visible_core_count = 1 } scheduling { diff --git a/mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown b/mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown index 369f11e5b04a..0ca4bb31c07a 100644 --- a/mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/compute_instance.html.markdown @@ -566,11 +566,13 @@ specified, then this instance will have no external IPv6 Internet access. Struct The `advanced_machine_features` block supports: -* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. +* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. -* `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. +* `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. -* `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). +* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default). + +* `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). The `reservation_affinity` block supports: diff --git a/mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown b/mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown index 1d65214ae30a..a2621e9d98f4 100644 --- a/mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/compute_instance_template.html.markdown @@ -722,11 +722,13 @@ The `specific_reservation` block supports: The `advanced_machine_features` block supports: -* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. +* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. -* `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. +* `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. -* `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). +* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default). + +* `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). ## Attributes Reference diff --git a/mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown b/mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown index a80285494177..316dd7ab257d 100644 --- a/mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/compute_region_instance_template.html.markdown @@ -682,11 +682,13 @@ The `specific_reservation` block supports: The `advanced_machine_features` block supports: -* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. +* `enable_nested_virtualization` - (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false. -* `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. +* `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. -* `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). +* `turbo_mode` - (Optional) Turbo frequency mode to use for the instance. Supported modes are currently either `ALL_CORE_MAX` or unset (default). + +* `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). ## Attributes Reference