我能够使用 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"
}
我怎样才能通过这个错误?
答案 0 :(得分:0)
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