【问题标题】:How to update disk in GCP using terraform?如何使用 terraform 在 GCP 中更新磁盘?
【发布时间】:2023-01-16 18:18:20
【问题描述】:

是否可以创建一个 terraform 模块来更新由另一个模块创建的特定资源?

目前,我有两个模块......

  1. linux-system:创建带有启动盘的 linux 虚拟机
  2. disk-updater:我打算用它来更新我从第一个模块创建的磁盘

    背后的原因是我想创建一个管道,通过像调整磁盘大小这样的地形来执行磁盘操作任务。

    data "google_compute_disk" "boot_disk" {
      name    = "linux-boot-disk"
      zone    = "europe-west2-b"
    }
    
    resource "google_compute_disk" "boot_disk" {
      name    = data.google_compute_disk.boot_disk.name
      zone    = data.google_compute_disk.boot_disk.zone
      size    = 25
    }
    

    我尝试使用数据块来检索现有磁盘详细信息并将其传递给资源块,希望更新同一磁盘,但它似乎只会尝试创建一个同名的新磁盘,这就是我收到此错误的原因。

    Error creating Disk: googleapi: Error 409: The resource ... already exists, alreadyExists
    

    我认为我做错了,有人可以给我建议如何在不使用我构建的第一个模块的情况下继续进行。顺便说一句,我是 terraform 的新手

【问题讨论】:

    标签: google-cloud-platform terraform cloud devops infrastructure-as-code


    【解决方案1】:

    更新由另一个模块创建的特定资源?

    不可以。您必须使用其原始定义来更新资源。

    从其他模块更新它的唯一方法是将 import 发送到其他模块,这是糟糕的设计,因为现在您将不得不定义相同的资源,从而导致状态文件不同步。

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2020-10-16
      • 2020-05-26
      • 2021-10-19
      • 2021-02-25
      • 2022-01-20
      • 2023-01-27
      • 2021-08-28
      • 2017-12-18
      相关资源
      最近更新 更多