
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
Use Terraform to automate network creation
/ 40
Use Terraform to create firewall rules
/ 30
Use Terraform to create virtual machines
/ 30
In this lab, you create a secure network infrastructure for your database migration projects. You create both public and private VPCs with appropriate firewall rules in each. You add virtual machines to each network and test the communication between them. You do all of this using Terraform to demonstrate a more real-world workflow that you can use in your migration projects.
In this lab, you learn how to perform the following tasks with Terraform:
In this task, you use Qwiklabs and perform initialization steps for your lab.
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
In the Navigation menu (), click Home.
In the Project info section, find your Project ID and copy and paste it into a text file. You will need it later.
Click the Activate Cloud Shell () icon in the upper right of the Console. The Cloud Shell terminal opens in a pane at the bottom of the window.
Create a directory called terraform-networks and change to it:
Enter ls
to verify that your files were created in the terraform-networks folder.
Click Open Editor in Cloud Shell, and then select the terraform-networks folder and open the provider.tf file.
Enter the following code to configure the Google Cloud Terraform provider:
Notice the variables in the above code. You create those and some other variables now.
You defined the variables in the previous file, and you set the variables in another file.
To confirm that the procedure has worked up to this point, in the Google Cloud Console, on the Navigation menu (), click VPC network. You should have one network named default.
In Cloud Shell, click Open Terminal. Make sure you are in the correct folder:
A message should indicate that "Terraform has been successfully initialized!".
Make sure there are no errors and look at what resources will be created.
The plan should tell you that two resources will be created: a network and a subnetwork.
The -auto-approve
parameter runs the script without prompting you.
You're not done configuring the network.
Click Check my progress to verify the objective.
At this point, you have used Terraform to create a network and subnet. Next, you create some firewall rules.
In Cloud Shell, click Open Editor. Open the vpc-firewall-rules-public.tf file in the terraform-networks folder.
To add a firewall rule that will allow SSH into machines in this network, add the following code:
Ping is useful for testing.
Click Check my progress to verify the objective.
Now you have a network and some firewall rules. Next, you add a test server to the network and see whether the firewall rules work.
This Terraform plug-in is used to generate a unique name for VMs added programatically.
When the commands complete, you should see the VM name and internal and external IP addresses.
From the Cloud Shell terminal, make sure you can ping the external IP address of that machine.
In the Console, go to the Compute Engine service to see the VM you just created.
Click SSH to make sure your firewall rule works, and then exit the SSH session.
Click Check my progress to verify the objective.
Use the configuration of the public network as a guide and create a second private network. In the variables.tf file, add a variable for the private subnet IP CIDR range, and set its value in the terraform.tfvars file.
Duplicate the vpc-network-public.tf file and change the names and variables appropriately.
Using the public firewall rules as a guide, add firewall rules for the private network. In the source_ranges section, don't allow traffic from all sources: only allow traffic from the public subnet IP CIDR range.
Create a test server in the private network, using the public one as a guide.
Congratulations! You have created a secure network infrastructure for your database migration projects. You created both public and private VPCs with appropriate firewall rules in each. You added virtual machines to each network and tested the communication between them. You did all of this using Terraform.
When you have completed your lab, click End Lab. Google Cloud Skills Boost 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 2022 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