Skip to content

Commit

Permalink
Add advanced_machine_features.enable_uefi_networking field to insta…
Browse files Browse the repository at this point in the history
…nce and templates (GoogleCloudPlatform#12423)
  • Loading branch information
karolgorc authored and amanMahendroo committed Dec 17, 2024
1 parent 74135ea commit 4d0b126
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,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 @@ -678,6 +679,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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -1133,6 +1134,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 @@ -988,6 +988,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 @@ -963,6 +963,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,
},
},
})
}

{{ if ne $.TargetVersionName `ga` -}}
func TestAccComputeInstanceTemplate_enableDisplay(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -3872,6 +3913,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)
}

{{ if ne $.TargetVersionName `ga` -}}
func testAccComputeInstanceTemplate_enableDisplay(suffix string) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,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 @@ -7260,6 +7287,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 @@ -940,6 +940,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 @@ -835,6 +835,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,
},
},
})
}


{{ if ne $.TargetVersionName `ga` -}}
func TestAccComputeRegionInstanceTemplate_enableDisplay(t *testing.T) {
Expand Down Expand Up @@ -3260,6 +3301,34 @@ 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)
}


{{ if ne $.TargetVersionName `ga` -}}
func testAccComputeRegionInstanceTemplate_enableDisplay(suffix string) string {
return fmt.Sprintf(`
Expand Down
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
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

0 comments on commit 4d0b126

Please sign in to comment.