Skip to content

Commit

Permalink
Add support for Updating Container Image (#12607)
Browse files Browse the repository at this point in the history
[upstream:692b686bf772d2e0ff847c492600dafd88faaf28]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Jan 13, 2025
1 parent e958959 commit aa4ef0c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12607.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
workbench: Changed `container_Image` field of `google_workbench_instance` resource to modifiable.
```
4 changes: 4 additions & 0 deletions google/services/workbench/resource_workbench_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")})
Expand Down
71 changes: 71 additions & 0 deletions google/services/workbench/resource_workbench_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit aa4ef0c

Please sign in to comment.