准备工作
- 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
- 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
- 在屏幕左上角,点击开始实验即可开始
Solve Task One
/ 100
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.
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:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Click Authorize.
Your output should now look like this:
Output:
Output:
Example output:
gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
This lab guides you through creating a firewall rule in Google Cloud using Terraform. You will learn how to define a firewall rule resource, configure its properties, and apply it to your Google Cloud project. This lab assumes you have a basic understanding of Google Cloud and Terraform.
Before you begin, configure your Google Cloud project. This includes setting the project ID, region, and zone. Also, enable the IAM API.
Set your Project ID:
Set your default region to
Set your default zone to
Terraform uses a state file to track the resources it manages. For collaboration and persistence, it's best to store this state file in a remote backend like Google Cloud Storage (GCS).
Create a Cloud Storage bucket. Ensure the bucket name is globally unique and prefixed with your project ID:
Enable versioning on the GCS bucket:
Now, you will define the firewall rule using Terraform's configuration language.
Create a new directory for your Terraform configuration files.
Create a file named firewall.tf and add the following code to define a firewall rule that allows SSH traffic (port 22) to instances with the tag ssh-allowed.
Create a variables.tf file to define variables used in firewall.tf and main.tf.
Create an outputs.tf file to output the firewall rule name.
Now you will apply the Terraform configuration to create the firewall rule in your Google Cloud project.
Run terraform init to enable Terraform.
Run terraform plan to preview the changes Terraform will make.
Run terraform apply to apply the configuration and create the firewall rule.
Verify that the firewall rule has been created in the Google Cloud Console.
To avoid incurring unnecessary costs, destroy the resources created in this lab.
Run terraform destroy to remove the firewall rule.
You have successfully created and destroyed a firewall rule in Google Cloud using Terraform. You have learned how to define firewall rules as code, manage their properties, and apply them to your Google Cloud project. This approach enables you to automate and manage your infrastructure in a consistent and repeatable manner.
Manual Last Updated Jul 22, 2025
Lab Last Tested Jul 22, 2025
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
一次一个实验
确认结束所有现有实验并开始此实验