Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create static IP using implicit dependency
/ 25
Create VM instance using implicit dependency
/ 25
Create cloud storage bucket using explicit dependency
/ 25
Create VM instance resource using explicit dependency
/ 25
Create static IP using implicit dependency
/ 25
Create VM instance using implicit dependency
/ 25
Create cloud storage bucket using explicit dependency
/ 25
Create VM instance resource using explicit dependency
/ 25
In this lab, you will create two VMs in the default network. We will use variables to define the VM's attributes at runtime and use output values to print a few resource attributes.
We will then add a static IP address to the first VM to examine how terraform handles implicit dependencies. We will then create a GCS bucket by mentioning explicit dependency to the VM to examine how terraform handles explicit dependency.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Let us initialize Terraform by setting Google as the provider.
The output should look like this (do not copy; this is example output):
Terraform comes pre-installed in Cloud Shell. With Terraform already installed, you can directly create infrastructure resources.
tfinfra folder, right-click on tfinfra folder and click New File.provider.tf:To save provider.tf, click File > Save.
Initialize Terraform by running the following commands:
The output should look like this (do not copy; this is example output):
Terraform has now installed the necessary plug-ins to interact with the Google Cloud API. Authentication is not required for API. The Cloud Shell credentials give access to the project and APIs.
Question:
In the remaining part of the lab, we will cover the two types of dependencies that Terraform can handle:
To demonstrate how Terraform infers an implicit dependency, we assign a static IP address to the VM instance.
Let us create a VM instance and parameterize its configuration by defining variables:
tfinfra folder and click New File.instance.tf:instance.tf, click File > Save.tfinfra folder and click New File to create a new file for variables.variables.tf, and then click OK.variables.tf:By giving instance_type a default value, you make the variable optional. The instance_name, and instance_zone are required, and you will define them at run time.
variable.tf, click File > Save.tfinfra folder and click New File to create a new file for outputs.outputs.tf, and then click OK.outputs.tf:outputs.tf, click File > Save.instance.tf
This should look familiar from the earlier example of adding a VM instance resource, except this time you're creating a google_compute_address resource type. This resource type allocates a reserved IP address to your project.
The final code is as shown below.
var.instance_name: myinstance
var.instance_zone:
var.instance_name: myinstance
var.instance_zone:
yes.In the Google Cloud console, verify that the resources were created.
In the Gooogle Cloud console, in the Navigation menu (), click Compute Engine > VM instances.
View that an instance named myinstance is created.
Verify the static IP address. On the Navigation menu (), click VPC networks > IP addresses > External IP addresses.
Click Check my progress to verify static IP address created
Click Check my progress to verify VM is created
Explicit dependencies are used to inform dependencies between resources that are not visible to Terraform. In this example, consider that you will run on your instance that expects to use a specific Cloud Storage bucket, but that dependency is configured inside the application code and thus not visible to Terraform. In that case, you can use depends_on to explicitly declare the dependency.
tfinfra folder and click New File.exp.tf:UNIQUE-BUCKET-NAME with a unique, valid name for a bucket. Using the project name and the date is usually a good way to create a unique bucket name.Notice that in our code the VM instance configuration is added before the GCS bucket. When executing Terraform apply you will notice that the order that resources are defined in a terraform configuration file has no effect on how Terraform applies your changes.
The final code is as show below:
To save exp.tf, click File > Save.
Run the following command to preview the resources created.
If prompted, enter the details for the instance creation as shown below:
var.instance_name: myinstance
var.instance_zone:
If prompted, enter the details for the instance creation as shown below:
var.instance_name: myinstance
var.instance_zone:
Confirm the planned actions by typing yes.
Observe that due explicit dependency, the compute instance is created after the creation of the Cloud Storage Bucket.
In the Google Cloud console, verify that the resources were created.
In the Google Cloud console, on the Navigation menu (), click Compute Engine > VM instances.
View the terraform-instance-2 instance created.
Verify the Cloud Storage bucket created. On the Navigation menu (), click Cloud Storage > Buckets.
Click Check my progress to verify that the bucket is created
Click Check my progress to verify that the VM is created
To understand how to read this graph, please visit this page
In this lab, you have a VM instance with a static IP address to view how implicit resource dependencies are handled with Terraform. You then created an explicit dependency by adding the depend_on argument so that you can create a GCS bucket before creating a VM instance. You also viewed the dependency graph that terraform uses to trace the order of resource creation.
When you have completed your lab, click End Lab. Google Skills removes the resources you've used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2026 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one
Complete this quick step to start your lab.