Skip to content

Commit

Permalink
Add support for Updating Container Image (GoogleCloudPlatform#12607)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcreddy-gcp committed Jan 13, 2025
1 parent d8bfe32 commit ddfb481
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ddfb481

Please sign in to comment.