准备工作
- 实验会创建一个 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 demonstrates how to use Terraform to create a Google Compute Engine (GCE) instance. You will define your infrastructure as code, allowing you to easily provision and manage your resources. This lab assumes you have basic knowledge of Google Cloud and Terraform.
Before you begin, ensure you have the following:
A Google Cloud project with billing enabled. You will need the Project ID for subsequent steps. The project ID will be:
Terraform installed on your local machine or in Cloud Shell. If using Cloud Shell, Terraform is pre-installed.
The Google Cloud SDK (gcloud) installed and configured. If using Cloud Shell, gcloud is pre-installed and authenticated.
Authenticate to your Google Cloud project. In Cloud Shell, this might be done automatically.
Set your Project ID to be:
Terraform uses a state file to track the resources it manages. For collaborative projects and increased reliability, it's best to store this state remotely in a Cloud Storage bucket.
Create a Cloud Storage bucket. The bucket name must be globally unique and should include your project ID as a prefix.
Enable versioning on the bucket. This allows you to revert to previous states if necessary.
Now, you will create the Terraform configuration files that define your GCE instance.
Create a file named main.tf with the following content:
Create a file named variables.tf (optional, but recommended for defining variables):
With the configuration files created, you can now initialize, plan, and apply your Terraform configuration.
Initialize Terraform. This downloads the necessary provider plugins.
Plan the changes. This shows you what Terraform will do before it makes any actual changes.
Apply the changes. This creates the GCE instance.
Once Terraform has finished, verify that the GCE instance has been created.
In the Google Cloud Console, navigate to Compute Engine > VM instances. You should see an instance named 'terraform-instance'.
Alternatively, use the gcloud command to list instances.
When you are finished, destroy the infrastructure to avoid incurring unnecessary costs.
Destroy the resources created by Terraform.
In this lab, you learned how to use Terraform to create a Google Compute Engine instance. By defining your infrastructure as code, you can easily manage and provision resources in a consistent and repeatable way. Remember to destroy your resources when you're finished to avoid unnecessary costs. Continue exploring Terraform's capabilities and integrate it into your Google Cloud workflows.
Manual Last Updated Jul 25, 2025
Lab Last Tested Jul 25, 2025
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
一次一个实验
确认结束所有现有实验并开始此实验