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.
📦 What You’ll Do in This Lab
Section titled “📦 What You’ll Do in This Lab”- Provision a JupyterLab environment using Vertex AI Workbench
- Explore the Iris dataset using Python and pandas
- Train and evaluate a simple ML model (RandomForest)
⚙️ Prerequisites
Section titled “⚙️ Prerequisites”Before getting started, make sure:
- You have a GCP project with billing enabled
- You have created a service account with the following roles:
Vertex AI AdminCompute AdminIAM Service Account UserService Usage Admin
- The following APIs are enabled:
vertexai.googleapis.comnotebooks.googleapis.comcloudresourcemanager.googleapis.com
🧱 Project Structure
Section titled “🧱 Project Structure”Directorygdg-workbench-lab/
Directory.env
- service_account_key.json
- main.tf
- variables.tf
- terraform.tfvars
- explore-iris.ipynb
- enable-apis.sh
- README.md
🛠 Step-by-Step Guide
Section titled “🛠 Step-by-Step Guide”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/fadharpra/terraform-vertex-ai-workbench.gitcd gdg-workbench-labInside 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 definitionsterraform.tfvars— variable valuesenable-apis.sh— script to enable required GCP APIsexplore-iris.ipynb— demo notebook for exploring the Iris dataset
Here’s a snippet from 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]}2. Add the variables.tf File
Section titled “2. Add the variables.tf File”Create a new file named variables.tf to declare the required variables:
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"}3. Edit the Variables
Section titled “3. Edit the Variables”Update terraform.tfvars with your own values:
project_id = "project-id-kalian"region = "asia-southeast2"zone = "asia-southeast2-a"service_account_key_path = ".env/service_account_key.json"4. Enable Required APIs
Section titled “4. Enable Required APIs”bash enable-apis.sh5. Deploy the Infrastructure
Section titled “5. Deploy the Infrastructure”terraform initterraform apply📊 Notebook Exploration
Section titled “📊 Notebook Exploration”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
🎓 Bonus Ideas
Section titled “🎓 Bonus Ideas”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
✅ Conclusion
Section titled “✅ Conclusion”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! 🎉