Skip to content

Commit

Permalink
add update test
Browse files Browse the repository at this point in the history
  • Loading branch information
bcreddy-gcp committed Oct 26, 2023
1 parent aa88c11 commit 7261e3a
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 4 deletions.
3 changes: 0 additions & 3 deletions mmv1/products/workbench/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,16 @@ properties:
properties:
- !ruby/object:Api::Type::Boolean
name: enableSecureBoot
send_empty_value: true
description: Optional. Defines whether the VM instance has Secure Boot enabled.
Secure Boot helps ensure that the system only runs authentic software by verifying
the digital signature of all boot components, and halting the boot process
if signature verification fails. Disabled by default.
- !ruby/object:Api::Type::Boolean
name: enableVtpm
send_empty_value: true
description: Optional. Defines whether the VM instance has the vTPM enabled.
Enabled by default.
- !ruby/object:Api::Type::Boolean
name: enableIntegrityMonitoring
send_empty_value: true
description: Optional. Defines whether the VM instance has integrity monitoring
enabled. Enables monitoring and attestation of the boot integrity of the VM
instance. The attestation is performed against the integrity policy baseline.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "google_workbench_instance" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['instance_name'] %>"
location = "us-west1-a"
location = "us-central1-a"
gce_setup {
machine_type = "n1-standard-1" // cant be e2 because of accelerator
accelerator_configs {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<% autogen_exception -%>
package workbench_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)


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

context := map[string]interface{}{
"service_account": envvar.GetTestServiceAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccWorkbenchInstance_basic(context),
},
{
ResourceName: "google_workbench_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "gce_setup.0.vm_image", "gce_setup.0.boot_disk.0.disk_encryption", "gce_setup.0.boot_disk.0.disk_type", "gce_setup.0.boot_disk.0.kms_key", "gce_setup.0.data_disks.0.disk_encryption", "gce_setup.0.data_disks.0.disk_type", "gce_setup.0.data_disks.0.kms_key", "labels", "terraform_labels"},
},
{
Config: testAccWorkbenchInstance_update(context),
},
{
ResourceName: "google_workbench_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "gce_setup.0.vm_image", "gce_setup.0.boot_disk.0.disk_encryption", "gce_setup.0.boot_disk.0.disk_type", "gce_setup.0.boot_disk.0.kms_key", "gce_setup.0.data_disks.0.disk_encryption", "gce_setup.0.data_disks.0.disk_type", "gce_setup.0.data_disks.0.kms_key", "labels", "terraform_labels"},
},
},
})
}

func testAccWorkbenchInstance_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_workbench_instance" "instance" {
name = "tf-test-workbench-instance%{random_suffix}"
location = "us-central1-a"
}
`, context)
}

func testAccWorkbenchInstance_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_workbench_instance" "instance" {
name = "tf-test-workbench-instance%{random_suffix}"
location = "us-central1-a"

gce_setup {
machine_type = "n1-standard-4"

accelerator_configs{
type = "NVIDIA_TESLA_T4"
core_count = 1
}

vm_image {
project = "deeplearning-platform-release"
family = "tf-latest-cpu"
}

service_accounts {
email = "%{service_account}"
}

boot_disk {
disk_size_gb = 110
disk_type = "PD_SSD"
disk_encryption = "GMEK"
kms_key = data.google_kms_crypto_key.crypto-key.id
}

data_disks {
disk_size_gb = 110
disk_type = "PD_SSD"
disk_encryption = "GMEK"
kms_key = data.google_kms_crypto_key.crypto-key.id
}

shielded_instance_config {
enable_secure_boot = true
enable_vtpm = true
enable_integrity_monitoring = true
}

network_interfaces {
network = data.google_compute_network.my_network.id
subnet = data.google_compute_subnetwork.my_subnetwork.id
nic_type = "GVNIC"
}

disable_public_ip = true

tags = ["abc","def"]

metadata = {
terraform = "true"
}

enable_ip_forwarding = true

gpu_driver_config {
enable_gpu_driver = true
custom_gpu_driver_path = "test_path"
}
}

instance_owners = [ "%{service_account}"]

disable_proxy_access = true

labels = {
k = "val"
}

}

data "google_compute_network" "my_network" {
name = "test-default"
}

data "google_compute_subnetwork" "my_subnetwork" {
name = "test-default"
region = "us-central1"
}

data "google_kms_key_ring" "keyring" {
name = "tftest-shared-keyring-1"
location = "global"
}

data "google_kms_crypto_key" "crypto-key" {
name = "tftest-shared-key-1"
key_ring = data.google_kms_key_ring.keyring.id
}
`, context)
}

0 comments on commit 7261e3a

Please sign in to comment.