0

刚刚运行terraform plan,它吐出了需要针对 GCP API 运行的配置。根据计划,它必须摧毁一些实体并重新创建它们。这些模块不相互依赖。下面的示例输出。

只是想知道创建(在这种情况下更像“覆盖”)是否发生在破坏之前,反之亦然,还是完全随机的?


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  + module.project_01.google_project_service.project_service[0]
      id:                 <computed>
      disable_on_destroy: "true"
      project:            "proj-**"
      service:            "compute.googleapis.com"

  + module.project_01.google_project_service.project_service[1]
      id:                 <computed>
      disable_on_destroy: "true"
      project:            "proj-**"
      service:            "cloudresourcemanager.googleapis.com"

  + module.project_01.google_project_service.project_service[2]
      id:                 <computed>
      disable_on_destroy: "true"
      project:            "proj-**"
      service:            "cloudbilling.googleapis.com"

  + module.project_01.google_project_service.project_service[3]
      id:                 <computed>
      disable_on_destroy: "true"
      project:            "proj-**"
      service:            "servicenetworking.googleapis.com"

  - module.project_01.google_project_service.project_service_billing

  - module.project_01.google_project_service.project_service_compute

  - module.project_01.google_project_service.project_service_crm


Plan: 4 to add, 0 to change, 3 to destroy.

------------------------------------------------------------------------
4

1 回答 1

1

在资源无法更新的情况下,changeTerraform会在创建新资源之前自动销毁资源。+-引用文档:

默认情况下,当 Terraform 必须更改由于远程 API 限制而无法就地更新的资源参数时,Terraform 将改为销毁现有对象,然后使用新配置的参数创建新的替换对象。

Terraform 资源本质上将是CRUD,并为四个动作中的每一个都编写了代码。在这种情况下会尝试更新change,但有时由于 API 限制而无法更新。在这些情况下, adestroy后跟 a create

但是,当没有更新代码和/或 API 端点可用时,可以在资源create_before_destroy中的块中:lifecycle

lifecycle {
  create_before_destroy = true
}

您可以在生命周期块文档中阅读有关此内容的更多信息。

于 2019-07-16T16:27:43.607 回答