云服务器内容精选

  • 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" 选项来禁止更新。
  • terraform apply terraform apply 命令用于执行资源的创建或变更。在操作执行前会进行一次人机交互,用于对资源创建和变更的确认。我们也可以使用 "-auto-approve" 选项跳过人机交互直接执行。 $ terraform applyAn 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 apply 的执行结果会保存在状态文件 (terraform.tfstate) 中,并且会显示定义的输出变量值。 Apply complete! Resources: 1 to add, 0 to change, 1 to destroy.Outputs:vpc_id = df507d37-bce2-4750-8873-f62abb3b085c