Skip to content

Commit

Permalink
Add support for visible_core_count for google_compute_instance resour…
Browse files Browse the repository at this point in the history
…ce (#6414) (#4635)

* add support for threads per core

* adding missing comma

* add support for threads per core

* guard changes with beta flag

* fixing typo

* fixing value

* guarding changes with flags

* annoting doc attribute with beta tag

* annoting doc attribute with beta tag

* missing comma

* adding guards for beta params

* adding guards for beta params

* incoprated comments

* incoprated comments

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 26, 2022
1 parent b4db714 commit 9ae00b3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/6414.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: Added support for param `visible_core_count` in `google_compute_instance` and `google_compute_instance_template` under `advanced_machine_features`
```
2 changes: 2 additions & 0 deletions google-beta/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func expandAdvancedMachineFeatures(d TerraformResourceData) *compute.AdvancedMac
return &compute.AdvancedMachineFeatures{
EnableNestedVirtualization: d.Get(prefix + ".enable_nested_virtualization").(bool),
ThreadsPerCore: int64(d.Get(prefix + ".threads_per_core").(int)),
VisibleCoreCount: int64(d.Get(prefix + ".visible_core_count").(int)),
}
}

Expand All @@ -406,6 +407,7 @@ func flattenAdvancedMachineFeatures(AdvancedMachineFeatures *compute.AdvancedMac
return []map[string]interface{}{{
"enable_nested_virtualization": AdvancedMachineFeatures.EnableNestedVirtualization,
"threads_per_core": AdvancedMachineFeatures.ThreadsPerCore,
"visible_core_count": AdvancedMachineFeatures.VisibleCoreCount,
}}
}

Expand Down
6 changes: 6 additions & 0 deletions google-beta/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ func resourceComputeInstance() *schema.Resource {
AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization", "advanced_machine_features.0.threads_per_core"},
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
},
"visible_core_count": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: []string{"advanced_machine_features.0.enable_nested_virtualization", "advanced_machine_features.0.threads_per_core", "advanced_machine_features.0.visible_core_count"},
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.`,
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions google-beta/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ func resourceComputeInstanceTemplate() *schema.Resource {
ForceNew: true,
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
},
"visible_core_count": {
Type: schema.TypeInt,
Optional: true,
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.`,
},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions google-beta/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,7 @@ resource "google_compute_instance_template" "foobar" {
advanced_machine_features {
threads_per_core = 1
enable_nested_virtualization = true
visible_core_count = 1
}
scheduling {
Expand Down
1 change: 1 addition & 0 deletions google-beta/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4746,6 +4746,7 @@ resource "google_compute_instance" "foobar" {
advanced_machine_features {
threads_per_core = 1
enable_nested_virtualization = true
visible_core_count = 1
}
allow_stopping_for_update = true
}
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 @@ -414,6 +414,8 @@ specified, then this instance will have no external IPv6 Internet access. Struct

* `threads_per_core` (Optional) he number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.

* `visible_core_count` (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).

<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
4 changes: 3 additions & 1 deletion website/docs/r/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ The `specific_reservation` block supports:

* `enable_nested_virtualization` (Optional) Defines whether the instance should have [nested virtualization](#on_host_maintenance) enabled. Defaults to false.

* `threads_per_core` (Optional) he number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.
* `threads_per_core` (Optional) The number of threads per physical core. To disable [simultaneous multithreading (SMT)](https://cloud.google.com/compute/docs/instances/disabling-smt) set this to 1.

* `visible_core_count` (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) The number of physical cores to expose to an instance. [visible cores info (VC)](https://cloud.google.com/compute/docs/instances/customize-visible-cores).

## Attributes Reference

Expand Down

0 comments on commit 9ae00b3

Please sign in to comment.