我正在尝试使用boot_disk和其他attached_disk使用terraform在gcp中创建一个vm实例。删除实例时,我找不到任何参数来自动删除附加的attached_disk。
自动删除选项在gcp控制台中可用.

Terraform代码:
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 {
}
}
}发布于 2021-06-11 22:02:21
不支持为附加磁盘设置自动删除功能。HashiCorp/Google决定不支持Terraform的这一功能。
参考此问题
如果告诉Terraform删除实例,但不删除磁盘,并且启用了自动删除,那么它不会专门删除磁盘,但是GCP仍然会删除它们。这种行为不会在计划运行中显示,因此可能导致不必要的结果,以及仍然显示磁盘存在的状态。
我的观点是Terraform应该管理从创造到毁灭的整个生命周期。对于要附加到新实例的磁盘,请将这些磁盘创建为Terraform的一部分,并作为HCL的一部分销毁它们。
https://stackoverflow.com/questions/67940260
复制相似问题