Skip to content

Labs: Provision Vertex AI Workbench with Terraform

🚀 A concise guide to help you provision Vertex AI Workbench using Terraform and explore the Iris dataset with Python. Ideal for workshops and self-paced labs.

🎤 A Short Story from Google I/O Extended Bogor 2025

Section titled “🎤 A Short Story from Google I/O Extended Bogor 2025”

Some time ago, I was invited to be a speaker/facilitator for the Code & Create - Build with AI Workshops Session 2 Dev Connect session at Google I/O Extended Bogor 2025.

Coming from a system engineering and infrastructure background, I’ll be honest — when the topic included AI, my first reaction was:

“Uh oh… this is way outside my comfort zone.”

I don’t come from an ML or Data Science background, and I genuinely struggled to understand many of GCP’s AI services at first.

But at the same time, I still wanted to share something relevant from my own perspective as an infrastructure engineer — specifically around automation and provisioning tools like Terraform.

So I treated this as a challenge:

  • Learn how to use Vertex AI Workbench
  • Provision everything from scratch
  • Package it into a hands-on lab focused on automation, not heavy modeling or training

🧠 From that experience, I learned one important thing:
AI–Infra collaboration isn’t about who knows more — it’s about enabling each other with the right tools.

ML teams need environments that are repeatable, secure, and scalable — and that’s exactly where automation tools like Terraform shine.

  • Provision a JupyterLab environment using Vertex AI Workbench
  • Explore the Iris dataset using Python and pandas
  • Train and evaluate a simple ML model (RandomForest)

Before getting started, make sure:

  1. You have a GCP project with billing enabled
  2. You have created a service account with the following roles:
    Vertex AI Admin
    Compute Admin
    IAM Service Account User
    Service Usage Admin
  3. The following APIs are enabled:
    vertexai.googleapis.com
    notebooks.googleapis.com
    cloudresourcemanager.googleapis.com
  • Directorygdg-workbench-lab/
    • Directory.env
      • service_account_key.json
  • main.tf
  • variables.tf
  • terraform.tfvars
  • explore-iris.ipynb
  • enable-apis.sh
  • README.md
Terminal window
git clone https://github.com/fadharpra/terraform-vertex-ai-workbench.git
cd gdg-workbench-lab

Inside the repository, you’ll find the main Terraform file, main.tf, which defines the Vertex AI Workbench resource used to deploy the JupyterLab environment.

You’ll also find supporting files:

  • variables.tf — input variable definitions
  • terraform.tfvars — variable values
  • enable-apis.sh — script to enable required GCP APIs
  • explore-iris.ipynb — demo notebook for exploring the Iris dataset

Here’s a snippet from main.tf:

main.tf
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 5.0.0"
}
}
}
provider "google" {
project = var.project_id
region = var.region
credentials = file(var.service_account_key_path)
}
resource "google_project_service" "resource_manager_api" {
service = "cloudresourcemanager.googleapis.com"
disable_on_destroy = true
}
resource "google_project_service" "enable_apis" {
for_each = toset([
"aiplatform.googleapis.com",
"datacatalog.googleapis.com",
"dataproc.googleapis.com"
])
service = each.key
disable_on_destroy = true
depends_on = [google_project_service.resource_manager_api]
}
resource "google_workbench_instance" "notebook" {
name = "gdg-workbench-demo"
location = var.zone
gce_setup {
machine_type = "n1-standard-1"
boot_disk {
disk_type = "PD_STANDARD"
disk_size_gb = 150
}
vm_image {
project = "cloud-notebooks-managed"
family = "workbench-instances"
}
disable_public_ip = false
enable_ip_forwarding = false
}
instance_owners = [var.user_email]
}

Create a new file named variables.tf to declare the required variables:

variables.tf
variable "project_id" {}
variable "region" {
default = "asia-southeast2"
}
variable "zone" {
default = "asia-southeast2-a"
}
variable "service_account_key_path" {
default = ".env/service_account_key.json"
}
variable "user_email" {
description = "Email user yang boleh akses notebook"
}

Update terraform.tfvars with your own values:

terraform.tfvars
project_id = "project-id-kalian"
region = "asia-southeast2"
zone = "asia-southeast2-a"
service_account_key_path = ".env/service_account_key.json"
user_email = "[email protected]"
Terminal window
bash enable-apis.sh
Terminal window
terraform init
terraform apply

Once the instance is running, open JupyterLab from the Vertex AI Workbench Console, upload explore-iris.ipynb, and run all cells.

You’ll see:

  • Dataset preview
  • Summary statistics
  • Training and evaluation of a simple ML model

You can extend this lab by:

  • Loading datasets from BigQuery
  • Uploading and loading models from GCS
  • Connecting to Vertex AI endpoints using the Python SDK

Vertex AI Workbench makes it easier, safer, and more repeatable to set up ML environments on GCP.
With Terraform, you can automate this setup and integrate it into your infrastructure workflow.

Happy hacking! 🎉