【问题标题】:How to set auto-delete option for additional attached_disk in gcp instance uing terraform?如何使用 terraform 为 gcp 实例中的其他附加磁盘设置自动删除选项?
【发布时间】:2021-08-28 14:08:54
【问题描述】:

我正在尝试使用 terraform 在 gcp 中创建一个带有 boot_disk 和附加 attach_disk 的 vm 实例。当实例被删除时,我找不到任何参数来自动删除附加的附加磁盘。

自动删除选项在 gcp 控制台中可用。

地形代码:

resource "google_compute_disk" "elastic-disk" {
    count   = var.no_of_elastic_intances
    name    = "elastic-disk-${count.index+1}-data"
    type    = "pd-standard"
    size    = "10"
}

resource "google_compute_instance" "elastic" {
  count        = var.no_of_elastic_intances
  name         = "${var.elastic_instance_name_prefix}-${count.index+1}"
  machine_type = var.elastic_instance_machine_type
  boot_disk {
    auto_delete = true
    mode = "READ_WRITE"
    initialize_params {
      image = var.elastic_instance_image_type
      type  = var.elastic_instance_disc_type
      size = var.elasitc_instance_disc_size
    }
  }
  attached_disk {
    source = "${element(google_compute_disk.elastic-disk.*.self_link, count.index)}"
    mode = "READ_WRITE"
  }
  network_interface {
    network = var.elastic_instance_network
    access_config {

    }
  }
}

【问题讨论】:

    标签: google-cloud-platform terraform terraform-provider-gcp


    【解决方案1】:

    不支持设置自动删除附加磁盘的功能。 HashiCorp/Google 决定不支持 Terraform 的此功能。

    参考这个issue:

    如果 Terraform 被告知要移除实例,而不是磁盘,并且 自动删除已启用,则不会专门删除 磁盘,但它们仍会被 GCP 删除。这种行为会 不会在计划运行中显示,因此可能会导致不想要的结果,因为 以及仍然显示磁盘存在的状态。

    我的观点是 Terraform 应该管理从创建到销毁的整个生命周期。对于要附加到新实例的磁盘,请将这些磁盘创建为 Terraform HCL 的一部分,并将它们作为 HCL 的一部分销毁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-19
      • 2023-01-27
      • 2023-01-16
      • 2022-06-17
      • 2014-01-17
      • 2016-02-28
      • 1970-01-01
      • 2019-02-25
      相关资源
      最近更新 更多