diff --git a/.changelog/12423.txt b/.changelog/12423.txt new file mode 100644 index 00000000000..3ffdd266e84 --- /dev/null +++ b/.changelog/12423.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: `google_compute_instance`, `google_compute_instance_template`, `google_compute_region_instance_template` now supports `advanced_machine_features.enable_uefi_networking` field +``` \ No newline at end of file diff --git a/google/services/compute/compute_instance_helpers.go b/google/services/compute/compute_instance_helpers.go index 17da34a2a0b..6192064ac5d 100644 --- a/google/services/compute/compute_instance_helpers.go +++ b/google/services/compute/compute_instance_helpers.go @@ -589,6 +589,7 @@ func expandAdvancedMachineFeatures(d tpgresource.TerraformResourceData) *compute TurboMode: d.Get(prefix + ".turbo_mode").(string), VisibleCoreCount: int64(d.Get(prefix + ".visible_core_count").(int)), PerformanceMonitoringUnit: d.Get(prefix + ".performance_monitoring_unit").(string), + EnableUefiNetworking: d.Get(prefix + ".enable_uefi_networking").(bool), } } @@ -602,6 +603,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac "turbo_mode": AdvancedMachineFeatures.TurboMode, "visible_core_count": AdvancedMachineFeatures.VisibleCoreCount, "performance_monitoring_unit": AdvancedMachineFeatures.PerformanceMonitoringUnit, + "enable_uefi_networking": AdvancedMachineFeatures.EnableUefiNetworking, }} } diff --git a/google/services/compute/resource_compute_instance.go b/google/services/compute/resource_compute_instance.go index a9b41a7f400..2805560f262 100644 --- a/google/services/compute/resource_compute_instance.go +++ b/google/services/compute/resource_compute_instance.go @@ -58,6 +58,7 @@ var ( "advanced_machine_features.0.turbo_mode", "advanced_machine_features.0.visible_core_count", "advanced_machine_features.0.performance_monitoring_unit", + "advanced_machine_features.0.enable_uefi_networking", } bootDiskKeys = []string{ @@ -1064,6 +1065,13 @@ be from 0 to 999,999,999 inclusive.`, ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false), Description: `The PMU is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are "STANDARD", "ENHANCED", and "ARCHITECTURAL".`, }, + "enable_uefi_networking": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + AtLeastOneOf: advancedMachineFeaturesKeys, + Description: `Whether to enable UEFI networking for the instance.`, + }, }, }, }, diff --git a/google/services/compute/resource_compute_instance_template.go b/google/services/compute/resource_compute_instance_template.go index 93acaac26ae..7d4f81aad6a 100644 --- a/google/services/compute/resource_compute_instance_template.go +++ b/google/services/compute/resource_compute_instance_template.go @@ -931,6 +931,12 @@ be from 0 to 999,999,999 inclusive.`, ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false), Description: `The PMU is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are "STANDARD", "ENHANCED", and "ARCHITECTURAL".`, }, + "enable_uefi_networking": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Description: `Whether to enable UEFI networking or not.`, + }, }, }, }, diff --git a/google/services/compute/resource_compute_instance_template_test.go b/google/services/compute/resource_compute_instance_template_test.go index bc022509975..ecbdd8e598a 100644 --- a/google/services/compute/resource_compute_instance_template_test.go +++ b/google/services/compute/resource_compute_instance_template_test.go @@ -877,6 +877,47 @@ func TestAccComputeInstanceTemplate_performanceMonitoringUnit(t *testing.T) { }) } +func TestAccComputeInstanceTemplate_enableUefiNetworking(t *testing.T) { + t.Parallel() + + var instanceTemplate compute.InstanceTemplate + context_1 := map[string]interface{}{ + "instance_name": fmt.Sprintf("tf-test-instance-template-%s", acctest.RandString(t, 10)), + "enable_uefi_networking": "false", + } + context_2 := map[string]interface{}{ + "instance_name": context_1["instance_name"].(string), + "enable_uefi_networking": "true", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeInstanceTemplate_enableUefiNetworking(context_1), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate), + resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.enable_uefi_networking", "false"), + ), + }, + { + Config: testAccComputeInstanceTemplate_enableUefiNetworking(context_2), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate), + resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.enable_uefi_networking", "true"), + ), + }, + { + ResourceName: "google_compute_instance_template.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccComputeInstanceTemplate_invalidDiskType(t *testing.T) { t.Parallel() @@ -3533,6 +3574,32 @@ resource "google_compute_instance_template" "foobar" { `, context) } +func testAccComputeInstanceTemplate_enableUefiNetworking(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_compute_image" "my_image" { + family = "ubuntu-2004-lts" + project = "ubuntu-os-cloud" +} + +resource "google_compute_instance_template" "foobar" { + name = "%{instance_name}" + machine_type = "n2-standard-2" + + disk { + source_image = data.google_compute_image.my_image.self_link + } + + network_interface { + network = "default" + } + + advanced_machine_features { + enable_uefi_networking = "%{enable_uefi_networking}" + } +} +`, context) +} + func testAccComputeInstanceTemplate_invalidDiskType(suffix string) string { return fmt.Sprintf(` # Use this datasource insead of hardcoded values when https://github.com/hashicorp/terraform/issues/22679 diff --git a/google/services/compute/resource_compute_instance_test.go b/google/services/compute/resource_compute_instance_test.go index 5ac5478f8d0..bcc6d3e6bbe 100644 --- a/google/services/compute/resource_compute_instance_test.go +++ b/google/services/compute/resource_compute_instance_test.go @@ -1512,6 +1512,33 @@ func TestAccComputeInstance_performanceMonitoringUnit(t *testing.T) { }) } +func TestAccComputeInstance_enableUefiNetworking(t *testing.T) { + t.Parallel() + + var instance compute.Instance + context_1 := map[string]interface{}{ + "instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)), + "enable_uefi_networking": "true", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeInstance_enableUefiNetworking(context_1), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceExists( + t, "google_compute_instance.foobar", &instance), + resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.enable_uefi_networking", "true"), + ), + }, + computeInstanceImportStep("us-central1-a", context_1["instance_name"].(string), []string{}), + }, + }) +} + func TestAccComputeInstance_soleTenantNodeAffinities(t *testing.T) { t.Parallel() @@ -6581,6 +6608,35 @@ resource "google_compute_instance" "foobar" { `, context) } +func testAccComputeInstance_enableUefiNetworking(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_compute_image" "my_image" { + family = "debian-12" + project = "debian-cloud" +} + +resource "google_compute_instance" "foobar" { + name = "%{instance_name}" + machine_type = "n2-standard-2" + zone = "us-central1-a" + + boot_disk { + initialize_params { + image = data.google_compute_image.my_image.self_link + } + } + + network_interface { + network = "default" + } + + advanced_machine_features { + enable_uefi_networking = "%{enable_uefi_networking}" + } +} +`, context) +} + func testAccComputeInstance_advancedMachineFeaturesUpdated(instance string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/google/services/compute/resource_compute_region_instance_template.go b/google/services/compute/resource_compute_region_instance_template.go index d73a22fa042..01ee8b45bda 100644 --- a/google/services/compute/resource_compute_region_instance_template.go +++ b/google/services/compute/resource_compute_region_instance_template.go @@ -897,6 +897,12 @@ be from 0 to 999,999,999 inclusive.`, ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false), Description: `The PMU is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are "STANDARD", "ENHANCED", and "ARCHITECTURAL".`, }, + "enable_uefi_networking": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Description: `Whether to enable UEFI networking or not.`, + }, }, }, }, diff --git a/google/services/compute/resource_compute_region_instance_template_test.go b/google/services/compute/resource_compute_region_instance_template_test.go index 7f0243cc4f8..b82e957d7b6 100644 --- a/google/services/compute/resource_compute_region_instance_template_test.go +++ b/google/services/compute/resource_compute_region_instance_template_test.go @@ -829,6 +829,47 @@ func TestAccComputeRegionInstanceTemplate_performanceMonitoringUnit(t *testing.T }) } +func TestAccComputeRegionInstanceTemplate_enableUefiNetworking(t *testing.T) { + t.Parallel() + + var instanceTemplate compute.InstanceTemplate + context_1 := map[string]interface{}{ + "instance_name": fmt.Sprintf("tf-test-instance-template-%s", acctest.RandString(t, 10)), + "enable_uefi_networking": "false", + } + context_2 := map[string]interface{}{ + "instance_name": context_1["instance_name"].(string), + "enable_uefi_networking": "true", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionInstanceTemplate_enableUefiNetworking(context_1), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate), + resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.enable_uefi_networking", "false"), + ), + }, + { + Config: testAccComputeRegionInstanceTemplate_enableUefiNetworking(context_2), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate), + resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.enable_uefi_networking", "true"), + ), + }, + { + ResourceName: "google_compute_region_instance_template.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccComputeRegionInstanceTemplate_invalidDiskType(t *testing.T) { t.Parallel() @@ -3060,6 +3101,33 @@ resource "google_compute_region_instance_template" "foobar" { `, context) } +func testAccComputeRegionInstanceTemplate_enableUefiNetworking(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_compute_image" "my_image" { + family = "ubuntu-2004-lts" + project = "ubuntu-os-cloud" +} + +resource "google_compute_region_instance_template" "foobar" { + name = "%{instance_name}" + region = "us-central1" + machine_type = "n2-standard-2" + + disk { + source_image = data.google_compute_image.my_image.self_link + } + + network_interface { + network = "default" + } + + advanced_machine_features { + enable_uefi_networking = "%{enable_uefi_networking}" + } +} +`, context) +} + func testAccComputeRegionInstanceTemplate_invalidDiskType(suffix string) string { return fmt.Sprintf(` # Use this datasource insead of hardcoded values when https://github.com/hashicorp/terraform/issues/22679 diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index a1af75e3830..acd46bad241 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -577,6 +577,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct * `performance_monitoring_unit` - (Optional) [The PMU](https://cloud.google.com/compute/docs/pmu-overview) is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are `STANDARD`, `ENHANCED`, and `ARCHITECTURAL`. +* `enable_uefi_networking` - (Optional) Whether to enable UEFI networking for instance creation. + The `reservation_affinity` block supports: * `type` - (Required) The type of reservation from which this instance can consume resources. diff --git a/website/docs/r/compute_instance_template.html.markdown b/website/docs/r/compute_instance_template.html.markdown index 3b009c3e0db..88a604fa44a 100644 --- a/website/docs/r/compute_instance_template.html.markdown +++ b/website/docs/r/compute_instance_template.html.markdown @@ -732,6 +732,8 @@ The `specific_reservation` block supports: * `performance_monitoring_unit` - (Optional) [The PMU](https://cloud.google.com/compute/docs/pmu-overview) is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are `STANDARD`, `ENHANCED`, and `ARCHITECTURAL`. +* `enable_uefi_networking` - (Optional) Whether to enable UEFI networking for instance creation. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are diff --git a/website/docs/r/compute_region_instance_template.html.markdown b/website/docs/r/compute_region_instance_template.html.markdown index 83b6a421bb0..9377858dd04 100644 --- a/website/docs/r/compute_region_instance_template.html.markdown +++ b/website/docs/r/compute_region_instance_template.html.markdown @@ -692,6 +692,8 @@ The `specific_reservation` block supports: * `performance_monitoring_unit` - (Optional) [The PMU](https://cloud.google.com/compute/docs/pmu-overview) is a hardware component within the CPU core that monitors how the processor runs code. Valid values for the level of PMU are `STANDARD`, `ENHANCED`, and `ARCHITECTURAL`. +* `enable_uefi_networking` - (Optional) Whether to enable UEFI networking for instance creation. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are