diff --git a/.changelog/12607.txt b/.changelog/12607.txt new file mode 100644 index 00000000000..07409549cf5 --- /dev/null +++ b/.changelog/12607.txt @@ -0,0 +1,3 @@ +```release-note:note +workbench: Changed `container_Image` field of `google_workbench_instance` resource to modifiable. +``` \ No newline at end of file diff --git a/google/services/workbench/resource_workbench_instance.go b/google/services/workbench/resource_workbench_instance.go index 150e55d22cb..9b70f4f40fb 100644 --- a/google/services/workbench/resource_workbench_instance.go +++ b/google/services/workbench/resource_workbench_instance.go @@ -1118,6 +1118,10 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e 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/google/services/workbench/resource_workbench_instance_test.go b/google/services/workbench/resource_workbench_instance_test.go index ba39529ad53..082921220e5 100644 --- a/google/services/workbench/resource_workbench_instance_test.go +++ b/google/services/workbench/resource_workbench_instance_test.go @@ -692,3 +692,74 @@ 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) +}