diff --git a/mmv1/templates/terraform/pre_update/workbench_instance.go.tmpl b/mmv1/templates/terraform/pre_update/workbench_instance.go.tmpl index f33e2afefa96..c74166b07abe 100644 --- a/mmv1/templates/terraform/pre_update/workbench_instance.go.tmpl +++ b/mmv1/templates/terraform/pre_update/workbench_instance.go.tmpl @@ -27,6 +27,10 @@ if d.HasChange("gce_setup.0.metadata") { if d.HasChange("effective_labels") { newUpdateMask = append(newUpdateMask, "labels") } +if d.HasChange("gce_setup.0.container_image") { + newUpdateMask = append(newUpdateMask, "gce_setup.container_image") + stopInstance = true +} updateMask = newUpdateMask // Overwrite the previously set mask. url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(newUpdateMask, ",")}) diff --git a/mmv1/third_party/terraform/services/workbench/resource_workbench_instance_test.go.tmpl b/mmv1/third_party/terraform/services/workbench/resource_workbench_instance_test.go.tmpl index 9df865d0e4b5..f031aa885e59 100644 --- a/mmv1/third_party/terraform/services/workbench/resource_workbench_instance_test.go.tmpl +++ b/mmv1/third_party/terraform/services/workbench/resource_workbench_instance_test.go.tmpl @@ -690,3 +690,75 @@ resource "google_workbench_instance" "instance" { } `, context) } + + +func TestAccWorkbenchInstance_updateCustomContainers(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "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_customcontainer(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "google_workbench_instance.instance", "state", "ACTIVE"), + ), + }, + { + ResourceName: "google_workbench_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels","desired_state"}, + }, + { + Config: testAccWorkbenchInstance_updatedcustomcontainer(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "google_workbench_instance.instance", "state", "ACTIVE"), + ), + }, + { + ResourceName: "google_workbench_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"name", "instance_owners", "location", "instance_id", "request_id", "labels", "terraform_labels","desired_state"}, + }, + }, + }) +} + +func testAccWorkbenchInstance_customcontainer(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 { + container_image { + repository = "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/base-cu113.py310" + tag = "latest" + } + } +} +`, context) +} + +func testAccWorkbenchInstance_updatedcustomcontainer(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 { + container_image { + repository = "gcr.io/deeplearning-platform-release/workbench-container" + tag = "20241117-2200-rc0" + } + } +} +`, context) +}