我可以使用terraform在GCP中创建实例和卷。但是,当我为卷创建快照时,我得到一个错误,并且磁盘不会连接:
Error: Error waiting for disk to attach: The disk resource 'projects/btgcp-iaas-dev/zones/us-east1-d/disks/dev-sql-td-data-disk' is already being used by 'projects/btgcp-iaas-dev/global/snapshots/dev-sql-td-data-disk-volume-snapshot'
on main.tf line 83, in resource "google_compute_attached_disk" "datadiskattach":
83: resource "google_compute_attached_disk" "datadiskattach" {下面是我定义磁盘、连接磁盘和快照资源的方式:
// Create additional disks
resource "google_compute_disk" "datadisk" {
name = var.data_disk_name
type = var.data_disk_type
size = var.data_disk_size
zone = var.zone
image = data.google_compute_image.sqlserverimage.self_link
labels = {
environment = "dev"
asv = "mycompanytools"
ownercontact = "myuser"
}
physical_block_size_bytes = 4096
}
// Attach additional disks
resource "google_compute_attached_disk" "datadiskattach" {
disk = google_compute_disk.datadisk.id
instance = google_compute_instance.default.id
}
// Create a snapshot of the datadisk volume
resource "google_compute_snapshot" "datadisksnapshot" {
name = var.datadisk_volume_snapshot_name
source_disk = google_compute_disk.datadisk.name
zone = var.zone
labels = {
my_label = var.datadisk_volume_snapshot_label
}
}下面是我在变量中命名它们的方式。在我得到的错误中,命名似乎有冲突:
// Create Data Disk Variables
variable "data_disk_name" {
description = "Value of the disk name for the data disk for the GCP instance"
type = string
default = "dev-sql-td-data-disk"
}
// Create Snapshot Variables
variable "datadisk_volume_snapshot_name" {
description = "Value of the datadisk name for the GCP instance root disk volume"
type = string
default = "dev-sql-td-data-disk-volume-snapshot"
}如何才能传递此错误?
发布于 2021-03-29 22:08:15
Terraform文档建议,“使用google_compute_attached_disk时,必须在连接了磁盘的google_compute_instance资源上使用lifecycle.ignore_changes = "attached_disk”,否则这两个资源将争夺连接的磁盘块的控制权“参考链接:https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_attached_disk
发布于 2021-11-11 13:20:09
将此代码添加到您的"google_compute_instance“中
lifecycle {
ignore_changes = [
attached_disk,
]
}发布于 2021-11-11 20:45:46
此外,还可以删除以下内容,因为Terraform会告诉您资源已经在使用中。
// Attach additional disks
resource "google_compute_attached_disk" "datadiskattach" {
disk = google_compute_disk.datadisk.id
instance = google_compute_instance.default.id
}https://stackoverflow.com/questions/66752805
复制相似问题