Skip to content

Commit

Permalink
Add beta support for confidentialInstanceType (#9847) (#17189)
Browse files Browse the repository at this point in the history
[upstream:93c04702df55bbf553790ee2720d46166f6501ae]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 5, 2024
1 parent a5c8d01 commit 40c6df8
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .changelog/9847.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `confidential_instance_config.confidential_instance_type` field to `google_compute_instance`, `google_compute_instance_template`, and `google_compute_region_instance_template` resources (beta)
```
4 changes: 2 additions & 2 deletions google/services/compute/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,12 @@ func expandConfidentialInstanceConfig(d tpgresource.TerraformResourceData) *comp
}
}

func flattenConfidentialInstanceConfig(ConfidentialInstanceConfig *compute.ConfidentialInstanceConfig) []map[string]bool {
func flattenConfidentialInstanceConfig(ConfidentialInstanceConfig *compute.ConfidentialInstanceConfig) []map[string]interface{} {
if ConfidentialInstanceConfig == nil {
return nil
}

return []map[string]bool{{
return []map[string]interface{}{{
"enable_confidential_compute": ConfidentialInstanceConfig.EnableConfidentialCompute,
}}
}
Expand Down
1 change: 1 addition & 0 deletions google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The Confidential VM config being used by the instance. on_host_maintenance has to be set to TERMINATE or this will fail to create.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"enable_confidential_compute": {
Type: schema.TypeBool,
Required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The Confidential VM config being used by the instance. on_host_maintenance has to be set to TERMINATE or this will fail to create.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"enable_confidential_compute": {
Type: schema.TypeBool,
Required: true,
Expand Down
20 changes: 12 additions & 8 deletions google/services/compute/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,10 @@ func TestAccComputeInstanceTemplate_ConfidentialInstanceConfigMain(t *testing.T)
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceTemplateConfidentialInstanceConfig(acctest.RandString(t, 10), true),
Config: testAccComputeInstanceTemplateConfidentialInstanceConfigEnable(acctest.RandString(t, 10), "SEV"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate, true),
testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate, true, "SEV"),
),
},
},
Expand Down Expand Up @@ -1593,7 +1593,7 @@ func testAccCheckComputeInstanceTemplateHasShieldedVmConfig(instanceTemplate *co
}
}

func testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(instanceTemplate *compute.InstanceTemplate, EnableConfidentialCompute bool) resource.TestCheckFunc {
func testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(instanceTemplate *compute.InstanceTemplate, EnableConfidentialCompute bool, ConfidentialInstanceType string) resource.TestCheckFunc {

return func(s *terraform.State) error {
if instanceTemplate.Properties.ConfidentialInstanceConfig.EnableConfidentialCompute != EnableConfidentialCompute {
Expand Down Expand Up @@ -2850,7 +2850,7 @@ resource "google_compute_instance_template" "foobar" {
`, suffix, enableSecureBoot, enableVtpm, enableIntegrityMonitoring)
}

func testAccComputeInstanceTemplateConfidentialInstanceConfig(suffix string, enableConfidentialCompute bool) string {
func testAccComputeInstanceTemplateConfidentialInstanceConfigEnable(suffix string, confidentialInstanceType string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "ubuntu-2004-lts"
Expand All @@ -2863,7 +2863,7 @@ resource "google_compute_instance_template" "foobar" {
disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
auto_delete = true
boot = true
}
Expand All @@ -2872,15 +2872,19 @@ resource "google_compute_instance_template" "foobar" {
}
confidential_instance_config {
enable_confidential_compute = %t
enable_confidential_compute = true
}
scheduling {
on_host_maintenance = "TERMINATE"
on_host_maintenance = "TERMINATE"
}
}
`, suffix, enableConfidentialCompute)
`, suffix)

}

func testAccComputeInstanceTemplateAdvancedMachineFeatures(suffix string) string {
Expand Down
17 changes: 11 additions & 6 deletions google/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,7 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
t.Parallel()

var instance compute.Instance

instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -1809,10 +1810,10 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstanceConfidentialInstanceConfig(instanceName, true),
Config: testAccComputeInstanceConfidentialInstanceConfigEnable(instanceName, "SEV"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceHasConfidentialInstanceConfig(&instance, true),
testAccCheckComputeInstanceHasConfidentialInstanceConfig(&instance, true, "SEV"),
),
},
},
Expand Down Expand Up @@ -3468,7 +3469,7 @@ func testAccCheckComputeInstanceHasShieldedVmConfig(instance *compute.Instance,
}
}

func testAccCheckComputeInstanceHasConfidentialInstanceConfig(instance *compute.Instance, EnableConfidentialCompute bool) resource.TestCheckFunc {
func testAccCheckComputeInstanceHasConfidentialInstanceConfig(instance *compute.Instance, EnableConfidentialCompute bool, ConfidentialInstanceType string) resource.TestCheckFunc {

return func(s *terraform.State) error {
if instance.ConfidentialInstanceConfig.EnableConfidentialCompute != EnableConfidentialCompute {
Expand Down Expand Up @@ -6598,7 +6599,7 @@ resource "google_compute_instance" "foobar" {
`, instance, enableSecureBoot, enableVtpm, enableIntegrityMonitoring)
}

func testAccComputeInstanceConfidentialInstanceConfig(instance string, enableConfidentialCompute bool) string {
func testAccComputeInstanceConfidentialInstanceConfigEnable(instance string, confidentialInstanceType string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "ubuntu-2004-lts"
Expand All @@ -6621,15 +6622,19 @@ resource "google_compute_instance" "foobar" {
}
confidential_instance_config {
enable_confidential_compute = %t
enable_confidential_compute = true
}
scheduling {
on_host_maintenance = "TERMINATE"
}
}
`, instance, enableConfidentialCompute)
`, instance)

}

func testAccComputeInstance_attributionLabelCreate(instance, add, strategy string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The Confidential VM config being used by the instance. on_host_maintenance has to be set to TERMINATE or this will fail to create.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"enable_confidential_compute": {
Type: schema.TypeBool,
Required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@ func TestAccComputeRegionInstanceTemplate_ConfidentialInstanceConfigMain(t *test
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionInstanceTemplateConfidentialInstanceConfig(acctest.RandString(t, 10), true),
Config: testAccComputeRegionInstanceTemplateConfidentialInstanceConfigEnable(acctest.RandString(t, 10), "SEV"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRegionInstanceTemplateExists(t, "google_compute_region_instance_template.foobar", &instanceTemplate),
testAccCheckComputeRegionInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate, true),
testAccCheckComputeRegionInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate, true, "SEV"),
),
},
},
Expand Down Expand Up @@ -1475,7 +1475,7 @@ func testAccCheckComputeRegionInstanceTemplateHasShieldedVmConfig(instanceTempla
}
}

func testAccCheckComputeRegionInstanceTemplateHasConfidentialInstanceConfig(instanceTemplate *compute.InstanceTemplate, EnableConfidentialCompute bool) resource.TestCheckFunc {
func testAccCheckComputeRegionInstanceTemplateHasConfidentialInstanceConfig(instanceTemplate *compute.InstanceTemplate, EnableConfidentialCompute bool, ConfidentialInstanceType string) resource.TestCheckFunc {

return func(s *terraform.State) error {
if instanceTemplate.Properties.ConfidentialInstanceConfig.EnableConfidentialCompute != EnableConfidentialCompute {
Expand Down Expand Up @@ -2555,7 +2555,7 @@ resource "google_compute_region_instance_template" "foobar" {
`, suffix, enableSecureBoot, enableVtpm, enableIntegrityMonitoring)
}

func testAccComputeRegionInstanceTemplateConfidentialInstanceConfig(suffix string, enableConfidentialCompute bool) string {
func testAccComputeRegionInstanceTemplateConfidentialInstanceConfigEnable(suffix string, confidentialInstanceType string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "ubuntu-2004-lts"
Expand All @@ -2578,15 +2578,19 @@ resource "google_compute_region_instance_template" "foobar" {
}
confidential_instance_config {
enable_confidential_compute = %t
enable_confidential_compute = true
}
scheduling {
on_host_maintenance = "TERMINATE"
}
}
`, suffix, enableConfidentialCompute)
`, suffix)

}

func testAccComputeRegionInstanceTemplateAdvancedMachineFeatures(suffix string) string {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ specified, then this instance will have no external IPv6 Internet access. Struct

<a name="nested_confidential_instance_config"></a>The `confidential_instance_config` block supports:

* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.
* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled with AMD SEV. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.

* `confidential_instance_type` (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Defines the confidential computing technology the instance uses. SEV is an AMD feature. One of the following values: `SEV`, `SEV_SNP`. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM. If `SEV_SNP`, currently [`min_cpu_platform`](#min_cpu_platform) has to be set to `"AMD Milan"` or this will fail to create the VM.

<a name="nested_advanced_machine_features"></a>The `advanced_machine_features` block supports:

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 @@ -651,7 +651,9 @@ The `specific_reservation` block supports:

<a name="nested_confidential_instance_config"></a>The `confidential_instance_config` block supports:

* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.
* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled with AMD SEV. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.

* `confidential_instance_type` (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Defines the confidential computing technology the instance uses. SEV is an AMD feature. One of the following values: `SEV`, `SEV_SNP`. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM. If `SEV_SNP`, currently [`min_cpu_platform`](#min_cpu_platform) has to be set to `"AMD Milan"` or this will fail to create the VM.

<a name="nested_network_performance_config"></a>The `network_performance_config` block supports:

Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/compute_region_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ The `specific_reservation` block supports:

<a name="nested_confidential_instance_config"></a>The `confidential_instance_config` block supports:

* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.
* `enable_confidential_compute` (Optional) Defines whether the instance should have confidential compute enabled on AMD SEV. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM.

* `confidential_instance_type` (Optional) [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) Defines the confidential computing technology the instance uses. SEV is an AMD feature. One of the following values: `SEV`, `SEV_SNP`. [`on_host_maintenance`](#on_host_maintenance) has to be set to TERMINATE or this will fail to create the VM. If `SEV_SNP`, currently [`min_cpu_platform`](#min_cpu_platform) has to be set to `"AMD Milan"` or this will fail to create the VM.

<a name="nested_network_performance_config"></a>The `network_performance_config` block supports:

Expand Down Expand Up @@ -720,4 +722,4 @@ When using the [`terraform import` command](https://developer.hashicorp.com/terr
$ terraform import google_compute_region_instance_template.default projects/{{project}}/regions/{{region}}/instanceTemplates/{{name}}
$ terraform import google_compute_region_instance_template.default {{project}}/{{name}}
$ terraform import google_compute_region_instance_template.default {{name}}
```
```

0 comments on commit 40c6df8

Please sign in to comment.