Skip to content

Commit be917a0

Browse files
Support advanced_machine_features.performance_monitoring_unit for instance and templates (#12281) (#20353)
[upstream:27bc9ea1a807ce259704399ba2287eaa6aa923b6] Signed-off-by: Modular Magician <[email protected]>
1 parent 0f742f5 commit be917a0

11 files changed

+293
-0
lines changed

.changelog/12281.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: `google_compute_instance`, `google_compute_instance_template` and `google_compute_region_instance_template` now support `advanced_machine_features.performance_monitoring_unit`
3+
```

google/services/compute/compute_instance_helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ func expandAdvancedMachineFeatures(d tpgresource.TerraformResourceData) *compute
588588
ThreadsPerCore: int64(d.Get(prefix + ".threads_per_core").(int)),
589589
TurboMode: d.Get(prefix + ".turbo_mode").(string),
590590
VisibleCoreCount: int64(d.Get(prefix + ".visible_core_count").(int)),
591+
PerformanceMonitoringUnit: d.Get(prefix + ".performance_monitoring_unit").(string),
591592
}
592593
}
593594

@@ -600,6 +601,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac
600601
"threads_per_core": AdvancedMachineFeatures.ThreadsPerCore,
601602
"turbo_mode": AdvancedMachineFeatures.TurboMode,
602603
"visible_core_count": AdvancedMachineFeatures.VisibleCoreCount,
604+
"performance_monitoring_unit": AdvancedMachineFeatures.PerformanceMonitoringUnit,
603605
}}
604606
}
605607

google/services/compute/resource_compute_instance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
"advanced_machine_features.0.threads_per_core",
5858
"advanced_machine_features.0.turbo_mode",
5959
"advanced_machine_features.0.visible_core_count",
60+
"advanced_machine_features.0.performance_monitoring_unit",
6061
}
6162

6263
bootDiskKeys = []string{
@@ -1056,6 +1057,13 @@ be from 0 to 999,999,999 inclusive.`,
10561057
AtLeastOneOf: advancedMachineFeaturesKeys,
10571058
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.`,
10581059
},
1060+
"performance_monitoring_unit": {
1061+
Type: schema.TypeString,
1062+
Optional: true,
1063+
AtLeastOneOf: advancedMachineFeaturesKeys,
1064+
ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false),
1065+
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".`,
1066+
},
10591067
},
10601068
},
10611069
},

google/services/compute/resource_compute_instance_template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,13 @@ be from 0 to 999,999,999 inclusive.`,
924924
ForceNew: true,
925925
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.`,
926926
},
927+
"performance_monitoring_unit": {
928+
Type: schema.TypeString,
929+
Optional: true,
930+
ForceNew: true,
931+
ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false),
932+
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".`,
933+
},
927934
},
928935
},
929936
},

google/services/compute/resource_compute_instance_template_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,68 @@ func TestAccComputeInstanceTemplate_AdvancedMachineFeatures(t *testing.T) {
815815
})
816816
}
817817

818+
func TestAccComputeInstanceTemplate_performanceMonitoringUnit(t *testing.T) {
819+
t.Parallel()
820+
821+
var instanceTemplate compute.InstanceTemplate
822+
context_1 := map[string]interface{}{
823+
"instance_name": fmt.Sprintf("tf-test-instance-template-%s", acctest.RandString(t, 10)),
824+
"performance_monitoring_unit": "STANDARD",
825+
}
826+
context_2 := map[string]interface{}{
827+
"instance_name": context_1["instance_name"].(string),
828+
"performance_monitoring_unit": "ENHANCED",
829+
}
830+
context_3 := map[string]interface{}{
831+
"instance_name": context_1["instance_name"].(string),
832+
"performance_monitoring_unit": "ARCHITECTURAL",
833+
}
834+
835+
acctest.VcrTest(t, resource.TestCase{
836+
PreCheck: func() { acctest.AccTestPreCheck(t) },
837+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
838+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
839+
Steps: []resource.TestStep{
840+
{
841+
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_1),
842+
Check: resource.ComposeTestCheckFunc(
843+
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
844+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "STANDARD"),
845+
),
846+
},
847+
{
848+
ResourceName: "google_compute_instance_template.foobar",
849+
ImportState: true,
850+
ImportStateVerify: true,
851+
},
852+
{
853+
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_2),
854+
Check: resource.ComposeTestCheckFunc(
855+
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
856+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ENHANCED"),
857+
),
858+
},
859+
{
860+
ResourceName: "google_compute_instance_template.foobar",
861+
ImportState: true,
862+
ImportStateVerify: true,
863+
},
864+
{
865+
Config: testAccComputeInstanceTemplate_performanceMonitoringUnit(context_3),
866+
Check: resource.ComposeTestCheckFunc(
867+
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
868+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
869+
),
870+
},
871+
{
872+
ResourceName: "google_compute_instance_template.foobar",
873+
ImportState: true,
874+
ImportStateVerify: true,
875+
},
876+
},
877+
})
878+
}
879+
818880
func TestAccComputeInstanceTemplate_invalidDiskType(t *testing.T) {
819881
t.Parallel()
820882

@@ -3445,6 +3507,32 @@ resource "google_compute_instance_template" "foobar" {
34453507
`, suffix)
34463508
}
34473509

3510+
func testAccComputeInstanceTemplate_performanceMonitoringUnit(context map[string]interface{}) string {
3511+
return acctest.Nprintf(`
3512+
data "google_compute_image" "my_image" {
3513+
family = "ubuntu-2004-lts"
3514+
project = "ubuntu-os-cloud"
3515+
}
3516+
3517+
resource "google_compute_instance_template" "foobar" {
3518+
name = "%{instance_name}"
3519+
machine_type = "c4-standard-96"
3520+
3521+
disk {
3522+
source_image = data.google_compute_image.my_image.self_link
3523+
}
3524+
3525+
network_interface {
3526+
network = "default"
3527+
}
3528+
3529+
advanced_machine_features {
3530+
performance_monitoring_unit = "%{performance_monitoring_unit}"
3531+
}
3532+
}
3533+
`, context)
3534+
}
3535+
34483536
func testAccComputeInstanceTemplate_invalidDiskType(suffix string) string {
34493537
return fmt.Sprintf(`
34503538
# Use this datasource insead of hardcoded values when https://github.com/hashicorp/terraform/issues/22679

google/services/compute/resource_compute_instance_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,58 @@ func TestAccComputeInstance_advancedMachineFeatures(t *testing.T) {
14601460
})
14611461
}
14621462

1463+
func TestAccComputeInstance_performanceMonitoringUnit(t *testing.T) {
1464+
t.Parallel()
1465+
1466+
var instance compute.Instance
1467+
context_1 := map[string]interface{}{
1468+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1469+
"performance_monitoring_unit": "STANDARD",
1470+
}
1471+
context_2 := map[string]interface{}{
1472+
"instance_name": context_1["instance_name"].(string),
1473+
"performance_monitoring_unit": "ENHANCED",
1474+
}
1475+
context_3 := map[string]interface{}{
1476+
"instance_name": context_1["instance_name"].(string),
1477+
"performance_monitoring_unit": "ARCHITECTURAL",
1478+
}
1479+
1480+
acctest.VcrTest(t, resource.TestCase{
1481+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1482+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1483+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
1484+
Steps: []resource.TestStep{
1485+
{
1486+
Config: testAccComputeInstance_performanceMonitoringUnit(context_1),
1487+
Check: resource.ComposeTestCheckFunc(
1488+
testAccCheckComputeInstanceExists(
1489+
t, "google_compute_instance.foobar", &instance),
1490+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "STANDARD"),
1491+
),
1492+
},
1493+
computeInstanceImportStep("us-central1-a", context_1["instance_name"].(string), []string{"allow_stopping_for_update"}),
1494+
{
1495+
Config: testAccComputeInstance_performanceMonitoringUnit(context_2),
1496+
Check: resource.ComposeTestCheckFunc(
1497+
testAccCheckComputeInstanceExists(
1498+
t, "google_compute_instance.foobar", &instance),
1499+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ENHANCED"),
1500+
),
1501+
},
1502+
computeInstanceImportStep("us-central1-a", context_2["instance_name"].(string), []string{"allow_stopping_for_update"}),
1503+
{
1504+
Config: testAccComputeInstance_performanceMonitoringUnit(context_3),
1505+
Check: resource.ComposeTestCheckFunc(
1506+
testAccCheckComputeInstanceExists(
1507+
t, "google_compute_instance.foobar", &instance),
1508+
resource.TestCheckResourceAttr("google_compute_instance.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
1509+
),
1510+
},
1511+
},
1512+
})
1513+
}
1514+
14631515
func TestAccComputeInstance_soleTenantNodeAffinities(t *testing.T) {
14641516
t.Parallel()
14651517

@@ -6498,6 +6550,37 @@ resource "google_compute_instance" "foobar" {
64986550
`, instance)
64996551
}
65006552

6553+
func testAccComputeInstance_performanceMonitoringUnit(context map[string]interface{}) string {
6554+
return acctest.Nprintf(`
6555+
data "google_compute_image" "my_image" {
6556+
family = "debian-12"
6557+
project = "debian-cloud"
6558+
}
6559+
6560+
resource "google_compute_instance" "foobar" {
6561+
name = "%{instance_name}"
6562+
machine_type = "c4-standard-96"
6563+
zone = "us-central1-a"
6564+
6565+
boot_disk {
6566+
initialize_params {
6567+
image = data.google_compute_image.my_image.self_link
6568+
}
6569+
}
6570+
6571+
network_interface {
6572+
network = "default"
6573+
}
6574+
6575+
advanced_machine_features {
6576+
performance_monitoring_unit = "%{performance_monitoring_unit}"
6577+
}
6578+
6579+
allow_stopping_for_update = true
6580+
}
6581+
`, context)
6582+
}
6583+
65016584
func testAccComputeInstance_advancedMachineFeaturesUpdated(instance string) string {
65026585
return fmt.Sprintf(`
65036586
data "google_compute_image" "my_image" {

google/services/compute/resource_compute_region_instance_template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,13 @@ be from 0 to 999,999,999 inclusive.`,
890890
ForceNew: true,
891891
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.`,
892892
},
893+
"performance_monitoring_unit": {
894+
Type: schema.TypeString,
895+
Optional: true,
896+
ForceNew: true,
897+
ValidateFunc: validation.StringInSlice([]string{"STANDARD", "ENHANCED", "ARCHITECTURAL"}, false),
898+
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".`,
899+
},
893900
},
894901
},
895902
},

google/services/compute/resource_compute_region_instance_template_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,68 @@ func TestAccComputeRegionInstanceTemplate_AdvancedMachineFeatures(t *testing.T)
767767
})
768768
}
769769

770+
func TestAccComputeRegionInstanceTemplate_performanceMonitoringUnit(t *testing.T) {
771+
t.Parallel()
772+
773+
var instanceTemplate compute.InstanceTemplate
774+
context_1 := map[string]interface{}{
775+
"instance_name": fmt.Sprintf("tf-test-instance-template-%s", acctest.RandString(t, 10)),
776+
"performance_monitoring_unit": "STANDARD",
777+
}
778+
context_2 := map[string]interface{}{
779+
"instance_name": context_1["instance_name"].(string),
780+
"performance_monitoring_unit": "ENHANCED",
781+
}
782+
context_3 := map[string]interface{}{
783+
"instance_name": context_1["instance_name"].(string),
784+
"performance_monitoring_unit": "ARCHITECTURAL",
785+
}
786+
787+
acctest.VcrTest(t, resource.TestCase{
788+
PreCheck: func() { acctest.AccTestPreCheck(t) },
789+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
790+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
791+
Steps: []resource.TestStep{
792+
{
793+
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(context_1),
794+
Check: resource.ComposeTestCheckFunc(
795+
testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate),
796+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "STANDARD"),
797+
),
798+
},
799+
{
800+
ResourceName: "google_compute_region_instance_template.foobar",
801+
ImportState: true,
802+
ImportStateVerify: true,
803+
},
804+
{
805+
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(context_2),
806+
Check: resource.ComposeTestCheckFunc(
807+
testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate),
808+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ENHANCED"),
809+
),
810+
},
811+
{
812+
ResourceName: "google_compute_region_instance_template.foobar",
813+
ImportState: true,
814+
ImportStateVerify: true,
815+
},
816+
{
817+
Config: testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(context_3),
818+
Check: resource.ComposeTestCheckFunc(
819+
testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate),
820+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "advanced_machine_features.0.performance_monitoring_unit", "ARCHITECTURAL"),
821+
),
822+
},
823+
{
824+
ResourceName: "google_compute_region_instance_template.foobar",
825+
ImportState: true,
826+
ImportStateVerify: true,
827+
},
828+
},
829+
})
830+
}
831+
770832
func TestAccComputeRegionInstanceTemplate_invalidDiskType(t *testing.T) {
771833
t.Parallel()
772834

@@ -2971,6 +3033,33 @@ resource "google_compute_region_instance_template" "foobar" {
29713033
`, suffix)
29723034
}
29733035

3036+
func testAccComputeRegionInstanceTemplate_performanceMonitoringUnit(context map[string]interface{}) string {
3037+
return acctest.Nprintf(`
3038+
data "google_compute_image" "my_image" {
3039+
family = "ubuntu-2004-lts"
3040+
project = "ubuntu-os-cloud"
3041+
}
3042+
3043+
resource "google_compute_region_instance_template" "foobar" {
3044+
name = "%{instance_name}"
3045+
region = "us-central1"
3046+
machine_type = "c4-standard-96"
3047+
3048+
disk {
3049+
source_image = data.google_compute_image.my_image.self_link
3050+
}
3051+
3052+
network_interface {
3053+
network = "default"
3054+
}
3055+
3056+
advanced_machine_features {
3057+
performance_monitoring_unit = "%{performance_monitoring_unit}"
3058+
}
3059+
}
3060+
`, context)
3061+
}
3062+
29743063
func testAccComputeRegionInstanceTemplate_invalidDiskType(suffix string) string {
29753064
return fmt.Sprintf(`
29763065
# Use this datasource insead of hardcoded values when https://github.com/hashicorp/terraform/issues/22679

website/docs/r/compute_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct
573573

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

576+
* `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`.
577+
576578
<a name="nested_reservation_affinity"></a>The `reservation_affinity` block supports:
577579

578580
* `type` - (Required) The type of reservation from which this instance can consume resources.

website/docs/r/compute_instance_template.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,8 @@ The `specific_reservation` block supports:
730730

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

733+
* `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`.
734+
733735
## Attributes Reference
734736

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

0 commit comments

Comments
 (0)