在这一步,你将首先初始化你的 Terraform 项目,然后运行 terraform plan 命令来创建一个执行计划。
在你可以计划任何更改之前,你必须初始化项目。terraform init 命令会扫描你的配置,下载所需的提供者(在本例中是 local_file 的提供者),并设置后端(backend)。
在你的终端中,首先运行 terraform init:
terraform init
初始化成功后,运行 terraform plan。这个命令是 Terraform 工作流程中的一个关键部分,因为它提供了一个更改的“试运行”(dry run)。它会向你展示 Terraform 将对你的基础设施执行的操作,而不会实际进行任何更改。这使得你可以在应用操作之前进行审查和验证。
terraform plan
Terraform 将读取你的配置文件,并将其与你基础设施的当前状态(目前为空)进行比较。然后它将显示一个操作计划。你应该会看到类似以下内容的输出,表明将要创建一个资源。
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
## local_file.example will be created
+ resource "local_file" "example" {
+ content = "Hello, Terraform!"
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./hello.txt"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
resource "local_file" "example" 旁边的 + 符号表示将创建此资源。输出详细说明了将在新文件上设置的所有属性。