首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >等待附加磁盘时发生GCP Terraform错误:磁盘资源磁盘资源已在使用中

等待附加磁盘时发生GCP Terraform错误:磁盘资源磁盘资源已在使用中
EN

Stack Overflow用户
提问于 2021-03-23 03:40:23
回答 3查看 125关注 0票数 0

我可以使用terraform在GCP中创建实例和卷。但是,当我为卷创建快照时,我得到一个错误,并且磁盘不会连接:

代码语言:javascript
复制
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" {

下面是我定义磁盘、连接磁盘和快照资源的方式:

代码语言:javascript
复制
// 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
  }
}

下面是我在变量中命名它们的方式。在我得到的错误中,命名似乎有冲突:

代码语言:javascript
复制
// 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"
}

如何才能传递此错误?

EN

回答 3

Stack Overflow用户

发布于 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

票数 0
EN

Stack Overflow用户

发布于 2021-11-11 13:20:09

将此代码添加到您的"google_compute_instance“中

代码语言:javascript
复制
lifecycle { 
    ignore_changes = [
      attached_disk,
      ] 
  }

more information

票数 0
EN

Stack Overflow用户

发布于 2021-11-11 20:45:46

此外,还可以删除以下内容,因为Terraform会告诉您资源已经在使用中。

代码语言:javascript
复制
// Attach additional disks
resource "google_compute_attached_disk" "datadiskattach" {
    disk = google_compute_disk.datadisk.id
    instance = google_compute_instance.default.id
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66752805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档