You need to enable JavaScript to run this app.
导航
基本命令
最近更新时间:2022.07.01 10:39:18首次发布时间:2022.05.17 12:06:30

terraform init

用于初始化工作目录,完成Provider、Backend、Modules等模块的加载。在同一个工作目录下,本命令可以重复执行。

说明

执行terraform init -upgrade=true命令可以更新Provider和Modules。

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of volcengine/volcengine...
- Installing volcengine/volcengine v1.0.0...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgardes to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* volcengine/volcengine: version = "~> 1.0.0"

Terraform has been successfully initialized!

terraform plan

用于创建执行前的计划,执行terraform apply命令前,需执行本命令预览检查待执行的变更是否符合预期,即云资源属性和状态文件是否存在差异。

说明

默认情况下,本命令首先会从远端更新资源的属性。资源较多时操作会耗时较长,您可以执行terraform plan -refresh=false禁止更新。

如果存在差异,Terraform会输出差异情况:

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or state storage.
...
Plan: 1 to add, 0 to change, 1 to destroy.
...

如果Terraform未检测到差异,会输出如下信息:

$ terraform plan
...
No changes. Infrastructure is up-to-date.

This means that Terraform did not detect ant differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

terraform apply

用于执行资源的创建或变更。操作执行前会进行一次人机交互,确认对资源的创建和变更,执行terraform apply -auto-approve命令可以跳过人机交互直接执行。

$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Terraform will perform the following action:
...
Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.
  Enter a value:

本命令的执行结果会保存在状态文件 (terraform.tfstate) 中,并且显示资源的输出变量值,如下所示:

Apply complete! Resources: 1 to add, 0 to change, 1 to destroy.

Outputs:

vpc_id = vpc-12323204

terraform destroy

用于删除资源。操作执行前会进行一次人机交互,确认对资源的销毁,执行terraform destroy -auto-approve命令可以跳过人机交互直接删除资源。

说明

terraform destroy命令会默认删除当前模块中的所有资源,请谨慎操作。

$ terraform destroy -auto-approve
...
Destroy complete! Resources: 1 destroyed.

如需删除后指定资源,格式为:-target=<资源类型>.<资源名称>。

$ terraform destroy -target=volcengine_subnet.foo
An execution plan has been generated and is show below.
Resource actions are indicated with the following symbols:
  - destroy
Terraform will perform the following actions:
  # volcengine_subnet.foo will be destroyed
  - resource "volcengine_subnet" "foo" {
    ...
  }
Plan: 0 to add, 0 to change, 1 to destroy.
...
Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.
  Enter a value:

terraform refresh

用于刷新state文件的配置,执行本命令后会调用远端API获取最新数据,并将结果写入state文件文件中。

terraform show

用于展示state文件中全部被管理的资源及其属性值。

terraform output

用于显示当前配置中的输出变量。根据配置中定义的输出变量逐一输出,规则为:<输出变量名> = <输出变量值>。