Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advanced_machine_features.enable_uefi_networking field to instance and templates #20531

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12423.txt
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions google/services/compute/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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,
}}
}

Expand Down
8 changes: 8 additions & 0 deletions google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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.`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions google/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

* `type` - (Required) The type of reservation from which this instance can consume resources.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down