Skip to content

Commit

Permalink
Support advanced_machine_features.performance_monitoring_unit for i…
Browse files Browse the repository at this point in the history
…nstance and templates (#12281)
  • Loading branch information
karolgorc authored Nov 15, 2024
1 parent c7b7dc4 commit 27bc9ea
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ func expandAdvancedMachineFeatures(d tpgresource.TerraformResourceData) *compute
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)),
PerformanceMonitoringUnit: d.Get(prefix + ".performance_monitoring_unit").(string),
}
}

Expand All @@ -676,6 +677,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac
"threads_per_core": AdvancedMachineFeatures.ThreadsPerCore,
"turbo_mode": AdvancedMachineFeatures.TurboMode,
"visible_core_count": AdvancedMachineFeatures.VisibleCoreCount,
"performance_monitoring_unit": AdvancedMachineFeatures.PerformanceMonitoringUnit,
{{"}}"}}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
"advanced_machine_features.0.threads_per_core",
"advanced_machine_features.0.turbo_mode",
"advanced_machine_features.0.visible_core_count",
"advanced_machine_features.0.performance_monitoring_unit",
}

bootDiskKeys = []string{
Expand Down Expand Up @@ -1125,6 +1126,13 @@ be from 0 to 999,999,999 inclusive.`,
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.`,
},
"performance_monitoring_unit": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: advancedMachineFeaturesKeys,
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".`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,13 @@ be from 0 to 999,999,999 inclusive.`,
ForceNew: true,
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.`,
},
"performance_monitoring_unit": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
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".`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,68 @@ func TestAccComputeInstanceTemplate_AdvancedMachineFeatures(t *testing.T) {
})
}

func TestAccComputeInstanceTemplate_performanceMonitoringUnit(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)),
"performance_monitoring_unit": "STANDARD",
}
context_2 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ENHANCED",
}
context_3 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ARCHITECTURAL",
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_1),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "STANDARD"),
),
},
{
ResourceName: "google_compute_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_2),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ENHANCED"),
),
},
{
ResourceName: "google_compute_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_3),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
),
},
{
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 @@ -3784,6 +3846,32 @@ resource "google_compute_instance_template" "foobar" {
`, suffix)
}

func testAccComputeInstanceTemplate_performanceMonitoringUnit(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 = "c4-standard-96"

disk {
source_image = data.google_compute_image.my_image.self_link
}

network_interface {
network = "default"
}

advanced_machine_features {
performance_monitoring_unit = "%{performance_monitoring_unit}"
}
}
`, 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 @@ -1468,6 +1468,58 @@ func TestAccComputeInstance_advancedMachineFeatures(t *testing.T) {
})
}

func TestAccComputeInstance_performanceMonitoringUnit(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)),
"performance_monitoring_unit": "STANDARD",
}
context_2 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ENHANCED",
}
context_3 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ARCHITECTURAL",
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstance_performanceMonitoringUnit(context_1),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
t, "google_compute_instance.foobar", &instance),
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "STANDARD"),
),
},
computeInstanceImportStep("us-central1-a", context_1["instance_name"].(string), []string{"allow_stopping_for_update"}),
{
Config: testAccComputeInstance_performanceMonitoringUnit(context_2),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
t, "google_compute_instance.foobar", &instance),
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ENHANCED"),
),
},
computeInstanceImportStep("us-central1-a", context_2["instance_name"].(string), []string{"allow_stopping_for_update"}),
{
Config: testAccComputeInstance_performanceMonitoringUnit(context_3),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
t, "google_compute_instance.foobar", &instance),
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
),
},
},
})
}

func TestAccComputeInstance_soleTenantNodeAffinities(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -7177,6 +7229,37 @@ resource "google_compute_instance" "foobar" {
`, instance)
}

func testAccComputeInstance_performanceMonitoringUnit(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 = "c4-standard-96"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}

network_interface {
network = "default"
}

advanced_machine_features {
performance_monitoring_unit = "%{performance_monitoring_unit}"
}

allow_stopping_for_update = true
}
`, 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 @@ -933,6 +933,13 @@ be from 0 to 999,999,999 inclusive.`,
ForceNew: true,
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.`,
},
"performance_monitoring_unit": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
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".`,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,69 @@ func TestAccComputeRegionInstanceTemplate_AdvancedMachineFeatures(t *testing.T)
})
}

func TestAccComputeRegionInstanceTemplate_performanceMonitoringUnit(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)),
"performance_monitoring_unit": "STANDARD",
}
context_2 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ENHANCED",
}
context_3 := map[string]interface{}{
"instance_name": context_1["instance_name"].(string),
"performance_monitoring_unit": "ARCHITECTURAL",
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(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.performance_monitoring_unit", "STANDARD"),
),
},
{
ResourceName: "google_compute_region_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(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.performance_monitoring_unit", "ENHANCED"),
),
},
{
ResourceName: "google_compute_region_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(context_3),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate),
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
),
},
{
ResourceName: "google_compute_region_instance_template.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}


{{ if ne $.TargetVersionName `ga` -}}
func TestAccComputeRegionInstanceTemplate_enableDisplay(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -3170,6 +3233,33 @@ resource "google_compute_region_instance_template" "foobar" {
`, suffix)
}

func testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(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 = "c4-standard-96"

disk {
source_image = data.google_compute_image.my_image.self_link
}

network_interface {
network = "default"
}

advanced_machine_features {
performance_monitoring_unit = "%{performance_monitoring_unit}"
}
}
`, 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 @@ -573,6 +573,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct

* `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).

* `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`.

<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 @@ -730,6 +730,8 @@ The `specific_reservation` block supports:

* `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).

* `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`.

## 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 @@ -690,6 +690,8 @@ The `specific_reservation` block supports:

* `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).

* `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`.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
Expand Down

0 comments on commit 27bc9ea

Please sign in to comment.