From b720f3564a49d1de6d53d2242ae750fb2e7160d4 Mon Sep 17 00:00:00 2001 From: Matthieu Mayran Date: Fri, 15 Jul 2022 22:47:15 +0100 Subject: [PATCH] Runtime patch (#6137) Co-authored-by: Shuya Ma <87669292+shuyama1@users.noreply.github.com> --- mmv1/products/notebooks/api.yaml | 17 ++- mmv1/products/notebooks/terraform.yaml | 5 + .../resource_notebooks_runtime_test.go.erb | 101 ++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 mmv1/third_party/terraform/tests/resource_notebooks_runtime_test.go.erb diff --git a/mmv1/products/notebooks/api.yaml b/mmv1/products/notebooks/api.yaml index fbd179f5645a..4f836d4819fb 100644 --- a/mmv1/products/notebooks/api.yaml +++ b/mmv1/products/notebooks/api.yaml @@ -475,6 +475,8 @@ objects: create_url: projects/{{project}}/locations/{{location}}/runtimes?runtimeId={{name}} self_link: projects/{{project}}/locations/{{location}}/runtimes/{{name}} create_verb: :POST + update_verb: :PATCH + update_mask: true # When set, if any parameter change, they will get recreated. # Use wisely because any `update_url:` in the hierarchy below this will get ignored. # input: true @@ -503,7 +505,7 @@ objects: - !ruby/object:Api::Type::String name: 'name' description: | - The name specified for the Notebook instance. + The name specified for the Notebook runtime. required: true input: true url_param_only: true @@ -673,6 +675,7 @@ objects: name: "containerImages" description: | Use a list of container images to start the notebook instance. + input: true item_type: !ruby/object:Api::Type::NestedObject properties: - !ruby/object:Api::Type::String @@ -689,6 +692,7 @@ objects: name: "encryptionConfig" description: | Encryption settings for virtual machine data disk. + input: true properties: - !ruby/object:Api::Type::String name: "kmsKey" @@ -702,6 +706,7 @@ objects: name: "shieldedInstanceConfig" description: | Shielded VM Instance configuration settings. + input: true properties: - !ruby/object:Api::Type::Boolean name: "enableSecureBoot" @@ -757,6 +762,7 @@ objects: configuring Private Service Access. * Shared VPC (network & subnet are required). Requires configuring Private Service Access. + input: true - !ruby/object:Api::Type::String name: "subnet" description: | @@ -766,6 +772,7 @@ objects: * `https://www.googleapis.com/compute/v1/projects/[project_id]/ regions/us-east1/subnetworks/sub0` * `projects/[project_id]/regions/us-east1/subnetworks/sub0` + input: true - !ruby/object:Api::Type::Boolean name: "internalIpOnly" description: | @@ -775,6 +782,7 @@ objects: `internal_ip_only` restriction can only be enabled for subnetwork enabled networks, and all dependencies must be configured to be accessible without external IP addresses. + input: true - !ruby/object:Api::Type::Array name: "tags" description: | @@ -810,10 +818,17 @@ objects: description: | The type of vNIC to be used on this interface. This may be gVNIC or VirtioNet. + input: true values: - UNSPECIFIED_NIC_TYPE - VIRTIO_NET - GVNIC + - !ruby/object:Api::Type::String + name: "reservedIpRange" + description: | + Reserved IP Range name is used for VPC Peering. The + subnetwork allocation will use the range *name* if it's assigned. + input: true - !ruby/object:Api::Type::Enum name: 'state' values: diff --git a/mmv1/products/notebooks/terraform.yaml b/mmv1/products/notebooks/terraform.yaml index 714a4fc8e4cf..60cee664e2b3 100644 --- a/mmv1/products/notebooks/terraform.yaml +++ b/mmv1/products/notebooks/terraform.yaml @@ -164,6 +164,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides softwareConfig: !ruby/object:Overrides::Terraform::PropertyOverride # API returns default idleShutdown (true) and default idleShutdownTimeout (180). default_from_api: true + update_mask_fields: + - "softwareConfig.idleShutdown" + - "softwareConfig.idleShutdownTimeout" + - "softwareConfig.customGpuDriverPath" + - "softwareConfig.postStartupScript" Location: !ruby/object:Overrides::Terraform::ResourceOverride properties: name: !ruby/object:Overrides::Terraform::PropertyOverride diff --git a/mmv1/third_party/terraform/tests/resource_notebooks_runtime_test.go.erb b/mmv1/third_party/terraform/tests/resource_notebooks_runtime_test.go.erb new file mode 100644 index 000000000000..4576ef33758e --- /dev/null +++ b/mmv1/third_party/terraform/tests/resource_notebooks_runtime_test.go.erb @@ -0,0 +1,101 @@ +<% autogen_exception -%> +package google + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccNotebooksRuntime_update(t *testing.T) { + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckNotebooksRuntimeDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccNotebooksRuntime_basic(context), + }, + { + ResourceName: "google_notebooks_runtime.runtime", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccNotebooksRuntime_update(context), + }, + { + ResourceName: "google_notebooks_runtime.runtime", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccNotebooksRuntime_basic(context), + }, + { + ResourceName: "google_notebooks_runtime.runtime", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + + +func testAccNotebooksRuntime_basic(context map[string]interface{}) string { + return Nprintf(` +resource "google_notebooks_runtime" "runtime" { + name = "tf-test-notebooks-runtime%{random_suffix}" + location = "us-central1" + access_config { + access_type = "SINGLE_USER" + runtime_owner = "admin@hashicorptest.com" + } + software_config {} + virtual_machine { + virtual_machine_config { + machine_type = "n1-standard-4" + data_disk { + initialize_params { + disk_size_gb = "100" + disk_type = "PD_STANDARD" + } + } + reserved_ip_range = "192.168.255.0/24" + } + } +} +`, context) +} + +func testAccNotebooksRuntime_update(context map[string]interface{}) string { + return Nprintf(` +resource "google_notebooks_runtime" "runtime" { + name = "tf-test-notebooks-runtime%{random_suffix}" + location = "us-central1" + access_config { + access_type = "SINGLE_USER" + runtime_owner = "admin@hashicorptest.com" + } + software_config { + idle_shutdown_timeout = "80" + } + virtual_machine { + virtual_machine_config { + machine_type = "n1-standard-4" + data_disk { + initialize_params { + disk_size_gb = "100" + disk_type = "PD_STANDARD" + } + } + reserved_ip_range = "192.168.255.0/24" + } + } +} +`, context) +}