♊️ GemiNews 🗞️
🏡
📰 Articles
🏷️ Tags
🧠 Queries
📈 Graphs
☁️ Stats
💁🏻 Assistant
Demo 1: Embeddings + Recommendation
Demo 2: Bella RAGa
Demo 3: NewRetriever
Demo 4: Assistant function calling
Editing article
Title
Summary
Content
<h3>Build Infrastructure on Google Cloud with Terraform — Google Challenge Lab Walkthrough</h3><p>This is a walkthrough of the <a href="https://partner.cloudskillsboost.google/focuses/16515?parent=catalog">challenge lab</a> from the course <a href="https://www.cloudskillsboost.google/course_templates/636">Build Infrastructure with Terraform on Google Cloud</a>.</p><p>This lab tests your ability to:</p><ul><li>Import existing infrastructure into your Terraform configuration.</li><li>Build and reference your own Terraform modules.</li><li>Add a remote backend to your configuration.</li><li>Use and implement a module from the Terraform Registry.</li><li>Re-provision, destroy, and update infrastructure.</li><li>Test connectivity between the resources you’ve created.</li></ul><h3>Intro to Challenge Labs</h3><p>Google provides an online learning platform called Google <a href="https://www.cloudskillsboost.google/">Cloud Skills Boost</a>, formerly known as QwikLabs. On this platform, you can follow training courses aligned to learning paths, to particular products, or for particular solutions.</p><p>One type of learning experience on this platform is called a <strong>quest</strong>. This is where you complete a number of guided hands-on labs, and then finally complete a <strong>Challenge Lab</strong>. The <strong>challenge lab</strong> differs from the other labs in that goals are specified, but very little guidance on <em>how</em> to achieve the goals is given.</p><p>I occasionally create walkthroughs of these challenge labs. The goal is not to help you cheat your way through the challenge labs! But rather:</p><ul><li>To show you what I believe to be an ideal route through the lab.</li><li>To help you with particular gotchas or blockers that are preventing you from completing the lab on your own.</li></ul><p>If you’re looking for help with challenge lab, then you’ve come to the right place. But I strongly urge you to work your way through the quest first, and to try the lab on your own, before reading further!</p><p>With all these labs, there are always many ways to go about solving the problem. I generally like to solve them using the Cloud Shell, since I can then document a more repeatable and programmatic approach. But of course, you can use the Cloud Console too.</p><h3>Overview of this Lab</h3><p>In this lab we’re expected to use Terraform to create, deploy and manage infrastructure on Google Cloud. We also need to import some mismanaged instances into our configuration and fix them.</p><h3>My Solution</h3><p>Let’s start by defining some variables we can use throughout this challenge. The actual variables will be provided to you when you start the lab.</p><pre>gcloud auth list<br><br>region=<ENTER REGION><br>zone=<ENTER ZONE><br>prj=<ENTER PRJ ID></pre><h4>Task 1 — Create the Configuration Files</h4><p>We’re told to create this folder structure:</p><pre>main.tf<br>variables.tf<br>modules/<br>└── instances<br>| ├── instances.tf<br>| ├── outputs.tf<br>| └── variables.tf<br>└── storage<br> ├── storage.tf<br> ├── outputs.tf<br> └── variables.tf</pre><p>We can do it like this:</p><pre># Create main.tf and variables.tf in the root directory<br>touch main.tf variables.tf<br><br># Create main directory and its files<br>mkdir -p modules/instances<br>mkdir modules/storage<br><br># Create the required files in the 'instances' module directory<br>touch modules/instances/instances.tf<br>touch modules/instances/outputs.tf<br>touch modules/instances/variables.tf<br><br># Create the required files in the 'storage' module directory<br>touch modules/storage/storage.tf<br>touch modules/storage/outputs.tf<br>touch modules/storage/variables.tf</pre><p>Now we update the variables.tf files to contain these variables:</p><pre>variable "region" {<br> description = "The Google Cloud region"<br> type = string<br> default = "Lab-supplied region"<br>}<br><br>variable "zone" {<br> description = "The Google Cloud zone"<br> type = string<br> default = "Lab-supplied zone"<br>}<br><br>variable "project_id" {<br> description = "The ID of the project in which to provision resources."<br> type = string<br> default = "Your project ID"<br>}</pre><p>Update the root module main.tf to include the Google Cloud Provider, which you can always look up in the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs">Terraform Registry</a>. We’re asked to include all three of our variables in our provider block.</p><pre>terraform {<br> required_providers {<br> google = {<br> source = "hashicorp/google"<br> }<br> }<br>}<br><br>provider "google" {<br> project = var.project_id<br> region = var.region<br> zone = var.zone<br>}</pre><p>Now we need to initialise Terraform. So run this command:</p><pre>terraform init</pre><h4>Task 2 — Import Infrastructure</h4><p>Here, the goal is to bring infrastructure under Terraform control, that has thus far been provisioned outside of Terraform.</p><p>We’re going to use the Terraform import workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/0*cLTWjcD7L2rsBcRO.png" /><figcaption>Terraform import workflow</figcaption></figure><p>These are the import steps:</p><ol><li>Identify the existing infrastructure to be imported.</li><li>Import the infrastructure into your <strong>Terraform state</strong>.</li><li>Write a <strong>Terraform configuration</strong> that matches that infrastructure.</li><li><strong>Review the Terraform plan</strong> to ensure that the configuration matches the expected state and infrastructure.</li><li><strong>Apply </strong>the configuration to update your Terraform state.</li></ol><h4>Identify the existing infrastructure to be imported</h4><p>Two GCE instances have already been created. Examine one of the existing instances, tf-instance-1 in the Cloud Console. We want to retrieve:</p><ul><li>Network</li><li>Machine type</li><li>Disk</li></ul><p>Next we need to include two calls to our instances module in our main.tf. They will contain empty definitions, so that we can import.</p><pre>module "tf_instance_1" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-1"<br> zone = var.zone<br> region = var.region<br>}<br><br>module "tf_instance_2" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-2"<br> zone = var.zone<br> region = var.region<br>}</pre><p>Remember that each module definition must have a unique label.</p><p>Now initialise:</p><pre>terraform init</pre><p>Now we write the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance">module configurations</a> in instances.tf. We’re told the arguments that need to be included in our minimal configuration:</p><pre>resource "google_compute_instance" "instance" {<br> name = var.instance_name<br> machine_type = "hard code from existing instance"<br> zone = var.zone<br><br> boot_disk {<br> initialize_params {<br> # image = "debian-cloud/debian-11"<br> image = "hard code from existing instance"<br> }<br> }<br><br> network_interface {<br> # network = "default"<br> network = "hard code from existing instance"<br> access_config {<br> // Ephemeral public IP<br> }<br> }<br><br> metadata_startup_script = <<-EOT<br> #!/bin/bash<br> EOT<br> allow_stopping_for_update = true<br>}</pre><p>Update variables.tf in the instance module, so we can pass in the instance_name:</p><pre>variable "instance_name" {<br> description = "The name of the instance."<br> type = string<br>}</pre><h4>Import the Existing Infrastructure into Terraform State</h4><pre>terraform import module.tf_instance_1.google_compute_instance.instance \<br> projects/$prj/zones/$zone/instances/tf-instance-1<br><br>terraform import module.tf_instance_2.google_compute_instance.instance \<br> projects/$prj/zones/$zone/instances/tf-instance-2<br><br># verify the import<br>terraform show</pre><p>The import should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1YafhrvtKcZG7MrQ.png" /><figcaption>terraform import</figcaption></figure><h4>Plan and Apply</h4><p>Now we update the instances in-place by running the apply:</p><pre>terraform plan<br>terraform apply</pre><h4>Task 3 — Configure a Remote Backend</h4><p>This is pretty easy. These are standard steps that you would run whenever we want to store Terraform state in a remote GCS backend:</p><ol><li>Provision a GCS bucket with Terraform.</li><li>Add a backend block that points to the new GCS bucket.</li><li>Reinitialise Terraform and migrate the state from the local state file to the remote backend.</li></ol><h4>Provision the GCS Bucket</h4><p>Add this resource definition to main.tf:</p><pre>resource "google_storage_bucket" "test-bucket-for-state" {<br> name = "Bucket Name You Are Given"<br> location = "US"<br> uniform_bucket_level_access = true<br><br> force_destroy = true<br>}</pre><p>And apply:</p><pre>terraform apply</pre><h4>Add the GCS Backend</h4><p>Modify main.tf and include the backend in the terraform block:</p><pre>terraform {<br> backend "gcs" {<br> bucket = var.project_id<br> prefix = "terraform/state"<br> }<br>}</pre><h4>Migrate the State</h4><p>This is where we migrate the Terraform state from the local state file into the GCS backend:</p><pre>terraform init -migrate-state</pre><p>It will ask you to confirm you want to migrate the state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qJ3EoohrCM8M5h7V.png" /><figcaption>Migrating Terraform state</figcaption></figure><h4>Task 4 — Modify and Update the Infrastructure</h4><p>We need to update variables.tf to include a machine_type:</p><pre>variable "machine_type" {<br> description = "The machine type of an instance"<br> type = string<br> default = "e2-standard-2"<br>}</pre><p>Then we need to modify instance.tf so that it can accept a machine_type parameter:</p><pre>resource "google_compute_instance" "instance" {<br> name = var.instance_name<br> machine_type = var.machine_type<br> zone = var.zone<br><br> ...</pre><p>Lastly, we need to modify main.tf such that we add the specified third instance to our main.tf, by calling the module for a third time. We don’t need to pass in the machine_type, as we’ve already set it to have a default.</p><p>Now initialise (because we’ve added another module instance) and apply.</p><pre>terraform init<br>terraform apply</pre><h4>Task 5 — Destroy Resources</h4><p>Now we remove the instance we previously added. Remove the call to this module from main.tf, then reapply:</p><pre>terraform init<br>terraform apply</pre><h4>Task 6 — Use a Module from the Registry</h4><p>We’re going to use the <a href="https://registry.terraform.io/modules/terraform-google-modules/network/google/6.0.0">Google Network Module</a>.</p><pre>module "network" {<br> source = "terraform-google-modules/network/google"<br> version = "6.0.0"<br><br> project_id = var.project_id<br> network_name = "Use Supplied VPC Name"<br> routing_mode = "GLOBAL"<br><br> subnets = [<br> {<br> subnet_name = "subnet-01"<br> subnet_ip = "10.10.10.0/24"<br> subnet_region = var.region<br> },<br> {<br> subnet_name = "subnet-02"<br> subnet_ip = "10.10.20.0/24"<br> subnet_region = var.region<br> }<br> ]<br>}</pre><p>Initialise and apply:</p><pre>terraform init<br>terraform apply</pre><p>Update instances module to take a network parameter and a subnet parameter.</p><p>In variables.tf:</p><pre>variable "network" {<br> description = "The network"<br> type = string<br>}<br><br>variable "subnet" {<br> description = "The subnet"<br> type = string<br>}</pre><p>In instance.tf:</p><pre>network_interface {<br> network = var.network<br> subnetwork = var.subnet<br><br> access_config {<br> // Ephemeral public IP<br> }<br>}</pre><p>Then update main.tf to create the instances like this:</p><pre>module "tf_instance_1" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-1"<br> zone = var.zone<br> region = var.region<br><br> network = module.network.network_name<br> subnet = "subnet-01"<br>}<br><br>module "tf_instance_2" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-2"<br> zone = var.zone<br> region = var.region<br> network = module.network.network_name<br> subnet = "subnet-02"<br>}</pre><pre>terraform init<br>terraform apply</pre><h4>Task 7 — Add a Firewall</h4><p>Update main.tf:</p><pre>resource "google_compute_firewall" "default" {<br> name = "tf-firewall"<br> network = module.network.network_name<br> direction = "INGRESS"<br> source_ranges = ["0.0.0.0/0"]<br><br> allow {<br> protocol = "tcp"<br> ports = ["80"]<br> }<br>}</pre><p>And one last apply…</p><pre>terraform apply</pre><p>And we’re done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a592373d3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/build-infrastructure-on-google-cloud-with-terraform-google-challenge-lab-walkthrough-30a592373d3e">Build Infrastructure on Google Cloud with Terraform — Google Challenge Lab Walkthrough</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
Author
Link
Published date
Image url
Feed url
Guid
Hidden blurb
--- !ruby/object:Feedjira::Parser::RSSEntry title: Build Infrastructure on Google Cloud with Terraform — Google Challenge Lab Walkthrough published: 2024-04-05 04:49:54.000000000 Z categories: - challenge-lab - google-cloud-platform - terraform - infrastructure - terraform-import entry_id: !ruby/object:Feedjira::Parser::GloballyUniqueIdentifier is_perma_link: 'false' guid: https://medium.com/p/30a592373d3e carlessian_info: news_filer_version: 2 newspaper: Google Cloud - Medium macro_region: Blogs content: '<h3>Build Infrastructure on Google Cloud with Terraform — Google Challenge Lab Walkthrough</h3><p>This is a walkthrough of the <a href="https://partner.cloudskillsboost.google/focuses/16515?parent=catalog">challenge lab</a> from the course <a href="https://www.cloudskillsboost.google/course_templates/636">Build Infrastructure with Terraform on Google Cloud</a>.</p><p>This lab tests your ability to:</p><ul><li>Import existing infrastructure into your Terraform configuration.</li><li>Build and reference your own Terraform modules.</li><li>Add a remote backend to your configuration.</li><li>Use and implement a module from the Terraform Registry.</li><li>Re-provision, destroy, and update infrastructure.</li><li>Test connectivity between the resources you’ve created.</li></ul><h3>Intro to Challenge Labs</h3><p>Google provides an online learning platform called Google <a href="https://www.cloudskillsboost.google/">Cloud Skills Boost</a>, formerly known as QwikLabs. On this platform, you can follow training courses aligned to learning paths, to particular products, or for particular solutions.</p><p>One type of learning experience on this platform is called a <strong>quest</strong>. This is where you complete a number of guided hands-on labs, and then finally complete a <strong>Challenge Lab</strong>. The <strong>challenge lab</strong> differs from the other labs in that goals are specified, but very little guidance on <em>how</em> to achieve the goals is given.</p><p>I occasionally create walkthroughs of these challenge labs. The goal is not to help you cheat your way through the challenge labs! But rather:</p><ul><li>To show you what I believe to be an ideal route through the lab.</li><li>To help you with particular gotchas or blockers that are preventing you from completing the lab on your own.</li></ul><p>If you’re looking for help with challenge lab, then you’ve come to the right place. But I strongly urge you to work your way through the quest first, and to try the lab on your own, before reading further!</p><p>With all these labs, there are always many ways to go about solving the problem. I generally like to solve them using the Cloud Shell, since I can then document a more repeatable and programmatic approach. But of course, you can use the Cloud Console too.</p><h3>Overview of this Lab</h3><p>In this lab we’re expected to use Terraform to create, deploy and manage infrastructure on Google Cloud. We also need to import some mismanaged instances into our configuration and fix them.</p><h3>My Solution</h3><p>Let’s start by defining some variables we can use throughout this challenge. The actual variables will be provided to you when you start the lab.</p><pre>gcloud auth list<br><br>region=<ENTER REGION><br>zone=<ENTER ZONE><br>prj=<ENTER PRJ ID></pre><h4>Task 1 — Create the Configuration Files</h4><p>We’re told to create this folder structure:</p><pre>main.tf<br>variables.tf<br>modules/<br>└── instances<br>| ├── instances.tf<br>| ├── outputs.tf<br>| └── variables.tf<br>└── storage<br> ├── storage.tf<br> ├── outputs.tf<br> └── variables.tf</pre><p>We can do it like this:</p><pre># Create main.tf and variables.tf in the root directory<br>touch main.tf variables.tf<br><br># Create main directory and its files<br>mkdir -p modules/instances<br>mkdir modules/storage<br><br># Create the required files in the 'instances' module directory<br>touch modules/instances/instances.tf<br>touch modules/instances/outputs.tf<br>touch modules/instances/variables.tf<br><br># Create the required files in the 'storage' module directory<br>touch modules/storage/storage.tf<br>touch modules/storage/outputs.tf<br>touch modules/storage/variables.tf</pre><p>Now we update the variables.tf files to contain these variables:</p><pre>variable "region" {<br> description = "The Google Cloud region"<br> type = string<br> default = "Lab-supplied region"<br>}<br><br>variable "zone" {<br> description = "The Google Cloud zone"<br> type = string<br> default = "Lab-supplied zone"<br>}<br><br>variable "project_id" {<br> description = "The ID of the project in which to provision resources."<br> type = string<br> default = "Your project ID"<br>}</pre><p>Update the root module main.tf to include the Google Cloud Provider, which you can always look up in the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs">Terraform Registry</a>. We’re asked to include all three of our variables in our provider block.</p><pre>terraform {<br> required_providers {<br> google = {<br> source = "hashicorp/google"<br> }<br> }<br>}<br><br>provider "google" {<br> project = var.project_id<br> region = var.region<br> zone = var.zone<br>}</pre><p>Now we need to initialise Terraform. So run this command:</p><pre>terraform init</pre><h4>Task 2 — Import Infrastructure</h4><p>Here, the goal is to bring infrastructure under Terraform control, that has thus far been provisioned outside of Terraform.</p><p>We’re going to use the Terraform import workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/0*cLTWjcD7L2rsBcRO.png" /><figcaption>Terraform import workflow</figcaption></figure><p>These are the import steps:</p><ol><li>Identify the existing infrastructure to be imported.</li><li>Import the infrastructure into your <strong>Terraform state</strong>.</li><li>Write a <strong>Terraform configuration</strong> that matches that infrastructure.</li><li><strong>Review the Terraform plan</strong> to ensure that the configuration matches the expected state and infrastructure.</li><li><strong>Apply </strong>the configuration to update your Terraform state.</li></ol><h4>Identify the existing infrastructure to be imported</h4><p>Two GCE instances have already been created. Examine one of the existing instances, tf-instance-1 in the Cloud Console. We want to retrieve:</p><ul><li>Network</li><li>Machine type</li><li>Disk</li></ul><p>Next we need to include two calls to our instances module in our main.tf. They will contain empty definitions, so that we can import.</p><pre>module "tf_instance_1" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-1"<br> zone = var.zone<br> region = var.region<br>}<br><br>module "tf_instance_2" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-2"<br> zone = var.zone<br> region = var.region<br>}</pre><p>Remember that each module definition must have a unique label.</p><p>Now initialise:</p><pre>terraform init</pre><p>Now we write the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance">module configurations</a> in instances.tf. We’re told the arguments that need to be included in our minimal configuration:</p><pre>resource "google_compute_instance" "instance" {<br> name = var.instance_name<br> machine_type = "hard code from existing instance"<br> zone = var.zone<br><br> boot_disk {<br> initialize_params {<br> # image = "debian-cloud/debian-11"<br> image = "hard code from existing instance"<br> }<br> }<br><br> network_interface {<br> # network = "default"<br> network = "hard code from existing instance"<br> access_config {<br> // Ephemeral public IP<br> }<br> }<br><br> metadata_startup_script = <<-EOT<br> #!/bin/bash<br> EOT<br> allow_stopping_for_update = true<br>}</pre><p>Update variables.tf in the instance module, so we can pass in the instance_name:</p><pre>variable "instance_name" {<br> description = "The name of the instance."<br> type = string<br>}</pre><h4>Import the Existing Infrastructure into Terraform State</h4><pre>terraform import module.tf_instance_1.google_compute_instance.instance \<br> projects/$prj/zones/$zone/instances/tf-instance-1<br><br>terraform import module.tf_instance_2.google_compute_instance.instance \<br> projects/$prj/zones/$zone/instances/tf-instance-2<br><br># verify the import<br>terraform show</pre><p>The import should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1YafhrvtKcZG7MrQ.png" /><figcaption>terraform import</figcaption></figure><h4>Plan and Apply</h4><p>Now we update the instances in-place by running the apply:</p><pre>terraform plan<br>terraform apply</pre><h4>Task 3 — Configure a Remote Backend</h4><p>This is pretty easy. These are standard steps that you would run whenever we want to store Terraform state in a remote GCS backend:</p><ol><li>Provision a GCS bucket with Terraform.</li><li>Add a backend block that points to the new GCS bucket.</li><li>Reinitialise Terraform and migrate the state from the local state file to the remote backend.</li></ol><h4>Provision the GCS Bucket</h4><p>Add this resource definition to main.tf:</p><pre>resource "google_storage_bucket" "test-bucket-for-state" {<br> name = "Bucket Name You Are Given"<br> location = "US"<br> uniform_bucket_level_access = true<br><br> force_destroy = true<br>}</pre><p>And apply:</p><pre>terraform apply</pre><h4>Add the GCS Backend</h4><p>Modify main.tf and include the backend in the terraform block:</p><pre>terraform {<br> backend "gcs" {<br> bucket = var.project_id<br> prefix = "terraform/state"<br> }<br>}</pre><h4>Migrate the State</h4><p>This is where we migrate the Terraform state from the local state file into the GCS backend:</p><pre>terraform init -migrate-state</pre><p>It will ask you to confirm you want to migrate the state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qJ3EoohrCM8M5h7V.png" /><figcaption>Migrating Terraform state</figcaption></figure><h4>Task 4 — Modify and Update the Infrastructure</h4><p>We need to update variables.tf to include a machine_type:</p><pre>variable "machine_type" {<br> description = "The machine type of an instance"<br> type = string<br> default = "e2-standard-2"<br>}</pre><p>Then we need to modify instance.tf so that it can accept a machine_type parameter:</p><pre>resource "google_compute_instance" "instance" {<br> name = var.instance_name<br> machine_type = var.machine_type<br> zone = var.zone<br><br> ...</pre><p>Lastly, we need to modify main.tf such that we add the specified third instance to our main.tf, by calling the module for a third time. We don’t need to pass in the machine_type, as we’ve already set it to have a default.</p><p>Now initialise (because we’ve added another module instance) and apply.</p><pre>terraform init<br>terraform apply</pre><h4>Task 5 — Destroy Resources</h4><p>Now we remove the instance we previously added. Remove the call to this module from main.tf, then reapply:</p><pre>terraform init<br>terraform apply</pre><h4>Task 6 — Use a Module from the Registry</h4><p>We’re going to use the <a href="https://registry.terraform.io/modules/terraform-google-modules/network/google/6.0.0">Google Network Module</a>.</p><pre>module "network" {<br> source = "terraform-google-modules/network/google"<br> version = "6.0.0"<br><br> project_id = var.project_id<br> network_name = "Use Supplied VPC Name"<br> routing_mode = "GLOBAL"<br><br> subnets = [<br> {<br> subnet_name = "subnet-01"<br> subnet_ip = "10.10.10.0/24"<br> subnet_region = var.region<br> },<br> {<br> subnet_name = "subnet-02"<br> subnet_ip = "10.10.20.0/24"<br> subnet_region = var.region<br> }<br> ]<br>}</pre><p>Initialise and apply:</p><pre>terraform init<br>terraform apply</pre><p>Update instances module to take a network parameter and a subnet parameter.</p><p>In variables.tf:</p><pre>variable "network" {<br> description = "The network"<br> type = string<br>}<br><br>variable "subnet" {<br> description = "The subnet"<br> type = string<br>}</pre><p>In instance.tf:</p><pre>network_interface {<br> network = var.network<br> subnetwork = var.subnet<br><br> access_config {<br> // Ephemeral public IP<br> }<br>}</pre><p>Then update main.tf to create the instances like this:</p><pre>module "tf_instance_1" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-1"<br> zone = var.zone<br> region = var.region<br><br> network = module.network.network_name<br> subnet = "subnet-01"<br>}<br><br>module "tf_instance_2" {<br> source = "./modules/instances"<br> instance_name = "tf-instance-2"<br> zone = var.zone<br> region = var.region<br> network = module.network.network_name<br> subnet = "subnet-02"<br>}</pre><pre>terraform init<br>terraform apply</pre><h4>Task 7 — Add a Firewall</h4><p>Update main.tf:</p><pre>resource "google_compute_firewall" "default" {<br> name = "tf-firewall"<br> network = module.network.network_name<br> direction = "INGRESS"<br> source_ranges = ["0.0.0.0/0"]<br><br> allow {<br> protocol = "tcp"<br> ports = ["80"]<br> }<br>}</pre><p>And one last apply…</p><pre>terraform apply</pre><p>And we’re done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a592373d3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/build-infrastructure-on-google-cloud-with-terraform-google-challenge-lab-walkthrough-30a592373d3e">Build Infrastructure on Google Cloud with Terraform — Google Challenge Lab Walkthrough</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>' rss_fields: - title - published - categories - entry_id - content - url - author url: https://medium.com/google-cloud/build-infrastructure-on-google-cloud-with-terraform-google-challenge-lab-walkthrough-30a592373d3e?source=rss----e52cf94d98af---4 author: Dazbo (Darren Lester)
Language
Active
Ricc internal notes
Imported via /usr/local/google/home/ricc/git/gemini-news-crawler/webapp/db/seeds.d/import-feedjira.rb on 2024-04-05 10:04:18 +0200. Content is EMPTY here. Entried: title,published,categories,entry_id,content,url,author. TODO add Newspaper: filename = /usr/local/google/home/ricc/git/gemini-news-crawler/webapp/db/seeds.d/../../../crawler/out/feedjira/Blogs/Google Cloud - Medium/2024-04-05-Build_Infrastructure_on_Google_Cloud_with_Terraform — Google_Cha-v2.yaml
Ricc source
Show this article
Back to articles