Terraform-基本命令:terraform plan

时间:2023-11-01 16:16:29

terraform plan

terraform plan 命令用于创建执行前的计划,是 terraform apply 执行前的一个预览方式,可以检查当前的变更是否符合预期。terraform plan 命令将检测云上资源的属性和状态文件是否存在差异,如果不一致,Terraform 会将差异结果显示在命令下方:

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

如果 Terraform 未检测到资源或根模块的更改,则 terraform plan 会输出如下提示:

$ terraform plan...No changes. Infrastructure is up-to-date.This means that Terraform did not detect ant differences between yourconfiguration and real physical resources that exist. As a result, noactions need to be performed.

默认情况下,terraform plan 命令首先会从远端更新资源的属性。在管理资源较多的情况下,该操作会耗时较长,我们可以使用 "-refresh=false" 选项来禁止更新。

support.huaweicloud.com/basics-terraform/terraform_0025.html