cd
terraform
:mkdir terraform
terraform
folder and then click New File.main.tf
as the filename and click OK.Open the main.tf
file in the Cloud Shell Editor.
Replace the PROJECT_NAME and LOCATION placeholders in the following Terraform configuration sample, and then copy the sample to the main.tf
file:
resource"google_project_service""notebooks"{provider=googleservice="notebooks.googleapis.com"disable_on_destroy=false}resource"google_notebooks_instance""basic_instance"{project="PROJECT_ID"name="notebooks-instance-basic"provider=googlelocation="LOCATION"machine_type="e2-medium"vm_image{project="deeplearning-platform-release"image_family="tf-ent-2-9-cu113-notebooks"}depends_on=[google_project_service.notebooks]}
PROJECT_ID: Enter the Google Cloud project ID.
LOCATION: Enter a region and zone for the user-managed notebooks instance. For example, us-west2-b
. For best network performance, select the region that is geographically closest to you. See the available user-managed notebooks locations.
Save the main.tf
file.
To open the Cloud Shell terminal, on the toolbar of the Cloud Shell Editor, click Open Terminal.
In the Cloud Shell terminal, run the following command to set the terraform
folder as the current working directory:
cd~/terraform
Run the following command:
terraforminit
Terraform initializes the working directory. The following output appears:
Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
The Terraform execution plan indicates the changes that Terraform plans to make to the Vertex AI infrastructure and services.
Run the following command to view the Terraform execution plan.
terraformplan
If prompted to authorize Cloud Shell, click Authorize. Cloud Shell uses the user's credentials by default upon authorizing.
You'll see output similar to the following:
Terraformusedtheselectedproviderstogeneratethefollowingexecutionplan.Resourceactionsareindicatedwiththefollowingsymbols:+createTerraformwillperformthefollowingactions: # google_notebooks_instance.basic_instance will be created+resource"google_notebooks_instance""basic_instance"{+create_time=(knownafterapply)+id=(knownafterapply)+labels=(knownafterapply)+location="us-west2-b"+machine_type="e2-medium"+name="notebooks-instance-basic"+network=(knownafterapply)+project="my_project"+proxy_uri=(knownafterapply)+service_account=(knownafterapply)+state=(knownafterapply)+subnet=(knownafterapply)+update_time=(knownafterapply)+shielded_instance_config{+enable_integrity_monitoring=(knownafterapply)+enable_secure_boot=(knownafterapply)+enable_vtpm=(knownafterapply)}+vm_image{+image_family="tf-ent-2-9-cu113-notebooks"+project="deeplearning-platform-release"}} # google_project_service.notebooks will be created+resource"google_project_service""notebooks"{+disable_on_destroy=false+id=(knownafterapply)+project=(knownafterapply)+service="notebooks.googleapis.com"}Plan:2toadd,0tochange,0todestroy.
my_project
indicates the Google Cloud project ID that you specified.
us-west2-b
indicates the region and zone for the user-managed notebooks instance that you specified.
Run the following command to apply the changes from the execution plan to the Vertex AI infrastructure and create the user-managed notebooks instance:
terraformapply
You'll see output similar to the following:
Terraformusedtheselectedproviderstogeneratethefollowingexecutionplan.Resourceactionsareindicatedwiththefollowingsymbols:+createTerraformwillperformthefollowingactions: # google_notebooks_instance.basic_instance will be created+resource"google_notebooks_instance""basic_instance"{+create_time=(knownafterapply)+id=(knownafterapply)+labels=(knownafterapply)+location="us-west2-b"+machine_type="e2-medium"+name="notebooks-instance-basic"+network=(knownafterapply)+project="my_project"+proxy_uri=(knownafterapply)+service_account=(knownafterapply)+state=(knownafterapply)+subnet=(knownafterapply)+update_time=(knownafterapply)+shielded_instance_config{+enable_integrity_monitoring=(knownafterapply)+enable_secure_boot=(knownafterapply)+enable_vtpm=(knownafterapply)}+vm_image{+image_family="tf-ent-2-9-cu113-notebooks"+project="deeplearning-platform-release"}} # google_project_service.notebooks will be created+resource"google_project_service""notebooks"{+disable_on_destroy=false+id=(knownafterapply)+project=(knownafterapply)+service="notebooks.googleapis.com"}Plan:2toadd,0tochange,0todestroy.Doyouwanttoperformtheseactions?Terraformwillperformtheactionsdescribedabove.Only'yes'willbeacceptedtoapprove.Enteravalue:
my_project
indicates the Google Cloud project ID that you specified.
us-west2-b
indicates the region and zone for the user-managed notebooks instance that you specified.
Type yes
and press Enter. You'll see output similar to the following:
Applycomplete!Resources:2added,0changed,0destroyed.
In the Google Cloud console, go to the User-managed notebooks page.
The new notebook named "notebooks-instance-basic" appears listed in the table. Note that the new user-managed notebooks instance might take a few minutes to get provisioned after you run terraform apply
.
Clean up the Google Cloud resources that you created during this tutorial. Follow these steps to avoid incurring unexpected charges from some of the resources:
In the Cloud Shell terminal, run the following command to set the terraform
folder as the current working directory:
cd~/terraform
To delete the Vertex AI resources that you created based on your Terraform configuration, run the following command:
terraformdestroy
You'll see output similar to the following:
Terraformusedtheselectedproviderstogeneratethefollowingexecutionplan.Resourceactionsareindicatedwiththefollowingsymbols:-destroyTerraformwillperformthefollowingactions: # google_notebooks_instance.basic_instance will be destroyed-resource"google_notebooks_instance""basic_instance"{-create_time="2022-12-01T21:14:05.065893475Z"->null-id="projects/my_project/locations/us-west2-b/instances/notebooks-instance-basic"->null-install_gpu_driver=false->null-labels={-"goog-caip-notebook"=""}->null-location="us-west2-b"->null-machine_type="e2-medium"->null-name="notebooks-instance-basic"->null-network="https://www.googleapis.com/compute/v1/projects/my_project/global/networks/default"->null-no_proxy_access=false->null-no_public_ip=false->null-project="my_project"->null-service_account="329223940713-compute@developer.gserviceaccount.com"->null-service_account_scopes=[]->null-state="PROVISIONING"->null-subnet="https://www.googleapis.com/compute/v1/projects/my_project/regions/us-west2/subnetworks/default"->null-tags=[]->null-update_time="2022-12-01T21:14:19.048432376Z"->null-shielded_instance_config{-enable_integrity_monitoring=true->null-enable_secure_boot=false->null-enable_vtpm=true->null}-vm_image{-image_family="tf-ent-2-9-cu113-notebooks"->null-project="deeplearning-platform-release"->null}} # google_project_service.notebooks will be destroyed-resource"google_project_service""notebooks"{-disable_on_destroy=false->null-id="my_project/notebooks.googleapis.com"->null-project="my_project"->null-service="notebooks.googleapis.com"->null}Plan:0toadd,0tochange,2todestroy.Doyoureallywanttodestroyallresources?Terraformwilldestroyallyourmanagedinfrastructure,asshownabove.Thereisnoundo.Only'yes'willbeacceptedtoconfirm.Enteravalue:
my_project
indicates the Google Cloud project ID that you specified.
us-west2-b
indicates the region and zone for the user-managed notebooks instance that you specified.
Type yes
and press Enter. You'll see output similar to the following:
Destroycomplete!Resources:2destroyed.
To verify that the user-managed notebooks instance was deleted, go to the User-managed notebooks page.
To delete the terraform
folder and its contents, right-click the terraform
folder in the Explorer pane and then click Delete.
When prompted, click OK to confirm.
This tutorial showed you how to use Terraform by creating only one configuration file and provisioning infrastructure based on one Terraform resource. You can also use Terraform in the following ways:
Add multiple Terraform resources to the same Terraform configuration file. For a list of Terraform resources for Vertex AI, see Terraform resources available for Vertex AI.
Create a directory structure comprising multiple folders and Terraform configuration files. For example, you can create a separate folder and Terraform configuration file for each type of Terraform resource.
Learn more about the google_notebooks_instance
Terraform resource in the Terraform registry.
Learn more about user-managed notebooks and Vertex AI Workbench.
Install Terraform on your local command-line interface.
Learn more about Terraform on the Terraform Developer website.
Refer to Terraform resource documentation in the Terraform registry.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-23 UTC.