hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.25k stars 1.7k forks source link

Allow idle timeout to be set on Notebook Instances (Vertex AI Workbench) #15654

Open oscar-barlow opened 10 months ago

oscar-barlow commented 10 months ago

Community Note

Description

Leaving notebook VMs running when they're not being actively used is a waste of money, so GCP offer an 'idle timeout' configuration option in the Vertex Workbench console. It would be really helpful to be able to configure this in Terraform, to save money.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_notebooks_instance" "instance" {
  name = "notebooks-instance"
  location = "us-west1-a"
  machine_type = "e2-medium"
  idle_shutdown = 60 # 1 hour in minutes
  vm_image {
    project      = "deeplearning-platform-release"
    image_family = "tf-latest-cpu"
  }
}

b/299312211

rileykarson commented 9 months ago

This may be managed through the unstructuredmetadata field. That's how it looks like it's done in the v2 API, at least, snippet from a REST response:

        "metadata": {
          "idle-timeout-seconds": "10800",
... other entries ...
        },
mahvar commented 6 months ago

@rileykarson Is that already doable via metadata?

enlightenalpha commented 6 months ago

Can confirm that the metadata approach described above worked for me:

"metadata": { "idle-timeout-seconds": "10800" }

bcreddy-gcp commented 5 months ago

@rileykarson Is there some documentation that'll help the users discover this better? Seems to be a very common question. Otherwise this ticket can be closed.

bcreddy-gcp commented 5 months ago

Documentation has been added here: https://cloud.google.com/vertex-ai/docs/workbench/instances/idle-shutdown

markustoivonen commented 5 months ago

Sorry if this is a stupid question but is the correct syntax?

resource "google_workbench_instance" "workbench_instance_test" {
  ...
  metadata = {
    idle-timeout-seconds = 1000
  }

Also, would it be possible to add the information to the resource documentation, considering that this is a new feature, and something that is new at least for those who are migrating from user managed notebooks.

bcreddy-gcp commented 5 months ago

Here's the syntax:

resource "google_workbench_instance" "workbench_instance_test" {
  ...
  metadata = {
    idle-timeout-seconds = "10800"
  }
sonnysideup commented 3 months ago

This worked for me as well. Thanks for the tip.

codrinsah commented 1 month ago

I haven't seen this mentioned yet, but if a notebook's idle timeout was already set e.g.

metadata = {
  idle-timeout-seconds = "10800"
}

In order to disable the idle timeout, you need to set the metadata to an empty string (not null or removing it!) like so:

metadata = {
  idle-timeout-seconds = ""
}

I noticed that simply removing it would not change the setting of the notebook.