arrow_back

Automating the Deployment of Networks with Terraform

Automating the Deployment of Networks with Terraform

1 heure 5 crédits

GSP460

Google Cloud self-paced labs logo

Overview

In this lab, you create a Terraform configuration with a module to automate the deployment of a custom network with resources. Specifically, you deploy 3 networks with firewall rules and VM instances, as shown in this network diagram:

A network diagram displaying three network topologies: VPC Network: mynetwork, VPC Network: management, and VPC Network: privatenet

What you'll do

In this lab, you learn how to perform the following tasks:

  • Create a configuration for a custom-mode network
  • Create a configuration for a firewall rule
  • Create a module for VM instances
  • Create a configuration for an auto-mode network
  • Create and deploy a configuration
  • Verify the deployment of a configuration

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud Console

  1. 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:

    • The Open Google Console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Console. 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.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  5. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:

Your Cloud Platform project in this session is set to YOUR_PROJECT_ID

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:

gcloud auth list
  1. Click Authorize.

  2. Your output should now look like this:

Output:

ACTIVE: * ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:

gcloud config list project

Output:

[core] project = <project_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Set up Terraform and Cloud Shell

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open-source tool that codifies APIs into declarative configuration files that can be shared among team members, treated as code, edited, reviewed, and versioned.

Install Terraform

In Cloud Shell, configure your Cloud Shell environment to use Terraform by installing it with the appropriate package.

  1. Download Terraform by running the following command:

wget https://releases.hashicorp.com/terraform/1.2.7/terraform_1.2.7_linux_amd64.zip Note: The available downloads for the latest version of Terraform can be found on the Terraform website. Terraform is distributed as a binary package for all supported platforms and architectures. Cloud Shell uses Linux 64-bit.
  1. Unzip Terraform by running the following command:

unzip terraform_1.2.7_linux_amd64.zip
  1. Set the PATH environmental variable to Terraform binaries:

export PATH="$PATH:$HOME/terraform" cd /usr/bin sudo ln -s $HOME/terraform cd $HOME source ~/.bashrc
  1. Confirm the Terraform installation by running the following command:

terraform --version

The output should look like this:

Terraform v0.12.24

Because you are logged in with Cloud Shell, Terraform will use your Google Cloud credentials.

  1. Export the Google Cloud project into an environment variable by running the following command in Cloud Shell:

export GOOGLE_PROJECT=$(gcloud config get-value project) Note: GOOGLE_PROJECT is known to Terraform and allows you to run Terraform without explicitly defining the project name or project ID within your Terraform scripts.
  1. Create a directory for your Terraform configuration by running the following command:

mkdir tfnet
  1. In Cloud Shell, click Open Editor to open Cloud Shell Editor. Click Open in a new window if required.

  2. Expand the tfnet folder in the left pane of the code editor.

Initialize Terraform

Terraform uses a plugin-based architecture to support the numerous infrastructure and service providers available. Each "Provider" is its own encapsulated binary distributed separately from Terraform itself. Initialize Terraform by setting Google as the provider.

  1. To create a new file in the tfnet folder, click File > New File.

  2. Name the new file provider.tf, and then open it.

  3. Copy the code into provider.tf:

provider "google" {}
  1. Initialize Terraform by running the following commands:

cd tfnet terraform init

The output should look like this:

* provider.google: version = "~> 3.63" Terraform has been successfully initialized!

You are now ready to work with Terraform in Cloud Shell.

Task 2. Create managementnet and its resources

Create the custom-mode network managementnet along with its firewall rule and VM instance (managementnet-us-vm).

Configure managementnet

Create a new configuration and define managementnet.

  1. To create a new file, click File > New File.

  2. Name the new file managementnet.tf, and then open it.

  3. Copy the following base code into managementnet.tf:

# Create the managementnet network resource [RESOURCE_TYPE] "managementnet" { name = [RESOURCE_NAME] #RESOURCE properties go here }

This base template is a great starting point for any Google Cloud resource. The name field allows you to name the resource, and the type field allows you to specify the Google Cloud resource that you want to create. You can also define properties, but these are optional for some resources.

  1. In managementnet.tf, replace [RESOURCE_TYPE] with "google_compute_network".
Note: The google_compute_network resource is a VPC network. Available resources can be found on the Google Cloud provider documentation. For more information on this specific resource, refer to the Terraform documentation.
  1. In managementnet.tf, replace [RESOURCE_NAME] with "managementnet".

  2. Add the following property to managementnet.tf:

auto_create_subnetworks = "false"

Unlike an auto-mode network, a custom mode network does not automatically create a subnetwork in each region. Therefore, you are setting auto_create_subnetworks to false.

  1. Verify that managementnet.tf looks like this:

# Create managementnet network resource "google_compute_network" "managementnet" { name = "managementnet" auto_create_subnetworks = "false" }
  1. To save managementnet.tf, click File > Save.

Add a subnet to managementnet

Add managementsubnet-us to the VPC network.

  1. Add the following resource to managementnet.tf:

# Create managementsubnet-us subnetwork resource "google_compute_subnetwork" "managementsubnet-us" { name = "managementsubnet-us" region = "us-central1" network = google_compute_network.managementnet.self_link ip_cidr_range = "10.130.0.0/20" } Note: The google_compute_subnetwork resource is a subnet. You are specifying the name, region, VPC network and IP CIDR range for managementsubnet-us. For more information on this specific resource, refer to the Terraform documentation.
  1. To save managementnet.tf, click File > Save.

Configure the firewall rule

Define a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on managementnet.

  1. Add the following base code to managementnet.tf:

# Add a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on managementnet resource [RESOURCE_TYPE] "managementnet-allow-http-ssh-rdp-icmp" { name = [RESOURCE_NAME] source_ranges = [ "0.0.0.0/0" ] #RESOURCE properties go here }
  1. In managementnet.tf, replace [RESOURCE_TYPE] with "google_compute_firewall":
Note: The google_compute_firewall resource is a firewall rule. For more information on this specific resource, refer to the Terraform documentation.
  1. In managementnet.tf, replace [RESOURCE_NAME] with "managementnet-allow-http-ssh-rdp-icmp".

  2. Add the following property to managementnet.tf:

network = google_compute_network.managementnet.self_link Note: Because this firewall rule depends on its network, you are using the google_compute_network.managementnet.self_link reference to instruct Terraform to resolve these resources in a dependent order. In this case, the network is created before the firewall rule.
  1. Add the following properties to managementnet.tf:

allow { protocol = "tcp" ports = ["22", "80", "3389"] } allow { protocol = "icmp" }

The list of allow rules specify which protocols and ports are permitted.

  1. Verify that your additions to managementnet.tf look like this:
# Create a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on managementnet resource "google_compute_firewall" "managementnet_allow_http_ssh_rdp_icmp" { name = "managementnet-allow-http-ssh-rdp-icmp" source_ranges = [ "0.0.0.0/0" ] network = google_compute_network.managementnet.self_link allow { protocol = "tcp" ports = ["22", "80", "3389"] } allow { protocol = "icmp" } }
  1. To save managementnet.tf, click File > Save.

Configure the VM instance

Define the VM instance by creating a VM instance module. A module is a reusable configuration inside a folder. You will use this module for all VM instances of this lab.

  1. To create a new folder inside tfnet, select the tfnet folder, and then click File > New Folder.
  2. Name the new folder instance.
  3. To create a new file inside instance, select the instance folder, and then click File > New File.
  4. Name the new file main.tf, and then open it.

You should have the following folder structure in Cloud Shell:

The folder structure displaying three tf files within the instance folder, which is within the tfnet folder

  1. Copy the following base code into main.tf:

resource [RESOURCE_TYPE] "vm_instance" { name = [RESOURCE_NAME] #RESOURCE properties go here }
  1. In main.tf, replace [RESOURCE_TYPE] with "google_compute_instance".
Note: The google_compute_instance resource is a Compute Engine instance. For more information on this specific resource, refer to the Terraform documentation.
  1. In main.tf, replace [RESOURCE_NAME] with var.instance_name.

Because you will be using this module for all VM instances, you are defining the instance name as an input variable. This allows you to control the name of the variable from managementnet.tf. For more information about input variables, refer to the Define Input Variables documentation.

  1. Add the following properties to main.tf:

zone = var.instance_zone machine_type = var.instance_type

These properties define the zone and machine type of the instance as input variables.

  1. Add the following properties to main.tf:

boot_disk { initialize_params { image = "debian-cloud/debian-11"} }

This property defines the boot disk to use the Debian 11 OS image. Because all four VM instances will use the same image, you can hard-code this property in the module.

  1. Add the following properties to main.tf:

network_interface { subnetwork = var.instance_subnetwork access_config { # Allocate a one-to-one NAT IP to the instance } }

This property defines the network interface by providing the subnetwork name as an input variable and the access configuration. Leaving the access configuration empty results in an ephemeral external IP address. For more information, see the Terraform documentation.

  1. Define the 4 input variables at the top of main.tf and verify that main.tf looks like this, including brackets {}:

variable "instance_name" {} variable "instance_zone" {} variable "instance_type" { default = "n1-standard-1" } variable "instance_subnetwork" {} resource "google_compute_instance" "vm_instance" { name = var.instance_name zone = var.instance_zone machine_type = var.instance_type boot_disk { initialize_params { image = "debian-cloud/debian-11" } } network_interface { subnetwork = var.instance_subnetwork access_config { # Allocate a one-to-one NAT IP to the instance } } }

By giving instance_type a default value, the variable is optional. The instance_name, instance_zone, and instance_subnetwork are required, and you will define them in managementnet.tf.

  1. To save main.tf, click File > Save.

  2. Add the following VM instance to managementnet.tf:

# Add the managementnet-us-vm instance module "managementnet-us-vm" { source = "./instance" instance_name = "managementnet-us-vm" instance_zone = "us-central1-a" instance_subnetwork = google_compute_subnetwork.managementsubnet-us.self_link }

This resource is leveraging the module in the instance folder and provides the name, zone, and network as inputs. Because this instance depends on a VPC network, you are using the google_compute_subnetwork.managementsubnet-us.self_link reference to instruct Terraform to resolve these resources in a dependent order. In this case, the subnet is created before the instance.

Note: The benefit of writing a Terraform module is that it can be reused across many configurations. Instead of writing your own module, you can also leverage existing modules from the Terraform Module registry.
  1. To save managementnet.tf, click File > Save.

Create managementnet and its resources

It's time to apply the managementnet configuration.

  1. Rewrite the Terraform configurations files to a canonical format and style by running the following command:

terraform fmt Note: If you get an error, revisit the previous steps to ensure that your configuration matches the lab instructions. If you cannot troubleshoot the issue of your configuration, look at these finished configurations:
  1. Initialize Terraform by running the following command:

terraform init

The output should look like this:

Initializing the backend... ... * provider.google: version = "~> 3.63" Terraform has been successfully initialized! Note: If you get an error, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.
  1. Create an execution plan by running the following command:

terraform plan

The output should look like this:

... Plan: 4 to add, 0 to change, 0 to destroy. ...

Terraform determined that the following 4 resources need to be added:

Name Description
managementnet VPC network
managementsubnet-us Subnet of managementnet in us-central1
managementnet_allow_http_ssh_rdp_icmp Firewall rule to allow HTTP, SSH, RDP and ICMP
managementnet-us-vm VM instance in us-central1-a
  1. Apply the desired changes by running the following command:

terraform apply
  1. Confirm the planned actions by typing:

yes

The output should look like this:

... Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

Notice that when the VPC network is created, the firewall rule and subnet are created. After the subnet is created, the VM instance is created. That's because the firewall rule and subnet relied on the network, and the VM instance relied on the subnet through self_link references.

Note: If you get an error during the execution, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.

Verify managementnet and its resources

In the Cloud Console, verify that the resources were created.

  1. In the Cloud Console, select Navigation menu > VPC network > VPC networks.
  2. View the managementnet VPC network with its subnetwork.
  3. In the left pane, click Firewall.
  4. View the managementnet_allow_http_ssh_rdp_icmp firewall rule for the VPC network that was created.
  5. Select Navigation menu > Compute Engine > VM instances.
  6. Note the managementnet-us-vm instance.
  7. Return to Cloud Shell.

Click Check my progress to verify the objective. Create managementnet and its resources

Task 3. Create privatenet and its resources

Create the custom-mode network privatenet along with its firewall rule and VM instance (privatenet-us-vm).

Configure privatenet

Create a new configuration and define privatenet.

  1. To create a new file in the tfnet folder, click File > New File.
  2. Name the new file privatenet.tf, and then open it.

You should have the following folder structure in Cloud Shell:

The folder structure where there are four tf files in the instance folder, which is within the tfnet folder

  1. Add the VPC network by copying the following code into privatenet.tf:

# Create privatenet network resource "google_compute_network" "privatenet" { name = "privatenet" auto_create_subnetworks = false }
  1. Add the privatesubnet-us subnet resource to privatenet.tf:

# Create privatesubnet-us subnetwork resource "google_compute_subnetwork" "privatesubnet-us" { name = "privatesubnet-us" region = "us-central1" network = google_compute_network.privatenet.self_link ip_cidr_range = "172.16.0.0/24" }
  1. Add the privatesubnet-eu subnet resource to privatenet.tf:

# Create privatesubnet-eu subnetwork resource "google_compute_subnetwork" "privatesubnet-eu" { name = "privatesubnet-eu" region = "europe-west1" network = google_compute_network.privatenet.self_link ip_cidr_range = "172.20.0.0/24" }
  1. To save privatenet.tf, click File > Save.

Configure the firewall rule

Define a firewall rule to allow HTTP, SSH, and RDP traffic on privatenet.

  1. Add the firewall resource to privatenet.tf:

# Create a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on privatenet resource "google_compute_firewall" "privatenet-allow-http-ssh-rdp-icmp" { name = "privatenet-allow-http-ssh-rdp-icmp" source_ranges = [ "0.0.0.0/0" ] network = google_compute_network.privatenet.self_link allow { protocol = "tcp" ports = ["22", "80", "3389"] } allow { protocol = "icmp" } } Note: Alternatively, you could create a module for the firewall rule because the only difference to the previous firewall rule is the VPC network that it applies to.
  1. To save privatenet.tf, click File > Save.

Configure the VM instance

Use the instance module to configure privatenet-us-vm.

  1. Add the VM instance resource to privatenet.tf:

# Add the privatenet-us-vm instance module "privatenet-us-vm" { source = "./instance" instance_name = "privatenet-us-vm" instance_zone = "us-central1-a" instance_subnetwork = google_compute_subnetwork.privatesubnet-us.self_link }
  1. To save privatenet.tf, click File > Save.

Create privatenet and its resources

It's time to apply the privatenet configuration.

  1. Rewrite the Terraform configurations files to a canonical format and style by running the following command:

terraform fmt Note: If you get an error, revisit the previous steps to ensure that your configuration matches the lab instructions. If you cannot troubleshoot the issue of your configuration, take a look at these finished configurations:
  1. Initialize Terraform by running the following command:

terraform init

The output should look like this:

Initializing the backend... ... * provider.google: version = "~> 3.63" Terraform has been successfully initialized! Note: If you get an error, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.
  1. Create an execution plan by running the following command:

terraform plan

The output should look like this:

... Plan: 5 to add, 0 to change, 0 to destroy. ...

Terraform determined that the following 5 resources need to be added:

Name Description
privatenet VPC network
privatesubnet-us Subnet of privatenet in us-central1
privatesubnet-eu Subnet of privatenet in europe-west1
privatenet-allow-http-ssh-rdp-icmp Firewall rule to allow HTTP, SSH, RDP and ICMP
privatenet-us-vm VM instance in us-central1-a
  1. Apply the desired changes by running the following command:

terraform apply
  1. Confirm the planned actions by typing:

yes

The output should look like this:

... Apply complete! Resources: 5 added, 0 changed, 0 destroyed. Note: If you get an error during the execution, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.

Verify privatenet and its resources

In the Cloud Console, verify that the resources were created.

  1. In the Cloud Console, select Navigation menu > VPC network > VPC networks.

  2. View the privatenet VPC network with its subnetworks.

  3. In the left pane, click VPC network > Firewall.

  4. View the privatenet_allow_http_ssh_rdp_icmp firewall rule for the VPC network that was created.

  5. Select Navigation menu > Compute Engine > VM instances.

  6. Note the internal IP addresses for privatenet-us-vm.

  7. For managementnet-us-vm, click SSH to launch a terminal and connect.

  8. To test connectivity to privatenet-us-vm's internal IP address, run the following command in the SSH terminal (replacing privatenet-us-vm's internal IP address with the value noted earlier):

ping -c 3 <Enter privatenet-us-vm's internal IP here> Note: This should not work because both VM instances are on separate VPC networks!
  1. Return to Cloud Shell.

Click Check my progress to verify the objective. Create privatenet and its resources

Task 4. Create mynetwork and its resources

Create the auto-mode network mynetwork along with its firewall rule and two VM instances (mynet_us_vm and mynet_eu_vm).

Configure mynetwork

Create a new configuration and define mynetwork.

  1. To create a new file in the tfnet folder, click File > New File.
  2. Name the new file mynetwork.tf, and then open it.

You should have the following folder structure in Cloud Shell:

The folder structure

  1. Copy the following code into mynetwork.tf:

# Create the mynetwork network resource "google_compute_network" "mynetwork" { name = "mynetwork" #RESOURCE properties go here }
  1. Add the following property to mynetwork.tf:

auto_create_subnetworks = "true"

By definition, an auto-mode network automatically creates a subnetwork in each region. Therefore, you are setting auto_create_subnetworks to true.

  1. Verify that mynetwork.tf looks like this:

# Create the mynetwork network resource "google_compute_network" "mynetwork" { name = "mynetwork" auto_create_subnetworks = "true" }
  1. To save mynetwork.tf, click File > Save.

Configure the firewall rule

Define a firewall rule to allow HTTP, SSH, and RDP traffic on mynetwork.

  1. Add the firewall resource to mynetwork.tf:

# Create a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on mynetwork resource "google_compute_firewall" "mynetwork-allow-http-ssh-rdp-icmp" { name = "mynetwork-allow-http-ssh-rdp-icmp" source_ranges = [ "0.0.0.0/0" ] network = google_compute_network.mynetwork.self_link allow { protocol = "tcp" ports = ["22", "80", "3389"] } allow { protocol = "icmp" } }
  1. To save mynetwork.tf, click File > Save.

Configure the VM instance

Use the instance module to configure mynetwork-us-vm and mynetwork-eu-vm.

  1. Add the following VM instances to mynetwork.tf:

# Create the mynet-us-vm instance module "mynet-us-vm" { source = "./instance" instance_name = "mynet-us-vm" instance_zone = "us-central1-a" instance_subnetwork = google_compute_network.mynetwork.self_link } # Create the mynet-eu-vm" instance module "mynet-eu-vm" { source = "./instance" instance_name = "mynet-eu-vm" instance_zone = "europe-west1-d" instance_subnetwork = google_compute_network.mynetwork.self_link }
  1. To save mynetwork.tf, click File > Save.

Create mynetwork and its resources

It's time to apply the mynetwork configuration.

  1. Rewrite the Terraform configurations files to a canonical format and style by running the following command:

terraform fmt Note: If you get an error, revisit the previous steps to ensure that your configuration matches the lab instructions. If you cannot troubleshoot the issue of your configuration, take a look at these finished configurations:
  1. Initialize Terraform by running the following command:

terraform init

The output should look like this:

Initializing the backend... ... * provider.google: version = "~> 3.63" Terraform has been successfully initialized! Note: If you get an error, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.
  1. Create an execution plan by running the following command:

terraform plan

The output should look like this:

... Plan: 4 to add, 0 to change, 0 to destroy. ...

Terraform determined that the following 4 resources need to be added:

Name Description
mynetwork VPC network
mynetwork-allow-http-ssh-rdp-icmp Firewall rule to allow HTTP, SSH, RDP and ICMP
mynet-us-vm VM instance in us-central1-a
mynet-eu-vm VM instance in europe-west1-d
  1. Apply the desired changes by running the following command:

terraform apply
  1. Confirm the planned actions by typing:

yes

The output should look like this:

... Apply complete! Resources: 4 added, 0 changed, 0 destroyed. Note: If you get an error during the execution, revisit the previous steps to ensure that you have the correct folder/file structure. If you cannot troubleshoot the issue of your configuration, refer to the finished configurations linked above. When you have corrected the issue, re-run the previous command.

Verify mynetwork and its resources

In the Cloud Console, verify that the resources were created.

  1. In the Cloud Console, select Navigation menu > VPC network > VPC networks.

  2. View the mynetwork VPC network with its subnetworks.

  3. In the left pane, click Firewall.

  4. View the mynetwork-allow-http-ssh-rdp-icmp firewall rule for the VPC network that was created.

  5. Select Navigation menu > Compute Engine > VM instances.

  6. View the mynet-us-vm and mynet-eu-vm instances.

  7. Note the internal IP addresses for mynet-eu-vm.

  8. For mynet-us-vm, click SSH to launch a terminal and connect.

  9. To test connectivity to mynet-eu-vm's internal IP address, run the following command in the SSH terminal (replacing mynet-eu-vm's internal IP address with the value noted earlier):

ping -c 3 <Enter mynet-eu-vm's internal IP here> Note: This should work because both VM instances are on the same network, and ICMP traffic is allowed!

Click Check my progress to verify the objective. Create mynetwork and its resources

Congratulations!

This concludes this self-paced lab, Automate the Deployment of Networks Using Terraform.

In this lab, you created Terraform configurations and modules to automate the deployment of a custom network. As the configuration changes, Terraform can determine what changed and create incremental execution plans, which allows you to build your overall configuration step-by-step.

The instance module allowed you to re-use the same resource configuration for multiple resources while providing properties as input variables. You can leverage the configurations and modules that you created as a starting point for future deployments.

Take your next lab

Learn more about Terraform by taking the Managing Cloud Infrastructure with Terraform Quest or any single lab in the Quest.

Next steps / Learn more

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated May 31, 2023

Lab Last Tested May 31, 2023

Copyright 2023 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.