我的 terraform 文件看起来像这样。
resource "google_compute_disk" "sqlserversecondary" {
name = "sql-server-secondary"
type = "pd-ssd"
zone = "us-central1-a"
size = "512"
}
resource "google_compute_instance" "sqlserver2016rc2" {
name = "sqlserver2016rc2"
machine_type = "n1-highmem-8"
tags = ["database", "sqlserver2016rc2"]
zone = "us-central1-a"
disk {
image = "sqlserver2016"
size = "120"
}
disk {
image = "sql-server-secondary"
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
GCE 中存在第二个磁盘,但是在这种特殊情况下我一直收到以下错误。
Error applying plan:
1 error(s) occurred:
* google_compute_instance.sqlserver2016rc2: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.disks[1].initializeParams': ''. Cannot specify initializeParams for non-boot persistent disks., invalid
答案1
对于第二个磁盘,您需要使用disk = "sql-server-secondary"
而不是image
作为标识符。此外,最好使用 Terraform 的插值语法(例如${...}
)引用第二个磁盘,以确保以适当的顺序创建和管理资源。
resource "google_compute_disk" "sqlserversecondary" {
name = "sql-server-secondary"
type = "pd-ssd"
zone = "us-central1-a"
size = "512"
}
resource "google_compute_instance" "sqlserver2016rc2" {
name = "sqlserver2016rc2"
machine_type = "n1-highmem-8"
tags = ["database", "sqlserver2016rc2"]
zone = "us-central1-a"
disk {
image = "ubuntu-1404-trusty-v20160114e"
size = "120"
}
disk {
disk = "${google_compute_disk.sqlserversecondary.name}" // s/image/disk
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
InitializeParams
Terraform为来自预先存在的映像的磁盘设置(代码) 导致您收到错误。似乎此场景中可能存在错误,即从现有映像附加非启动磁盘,但我仍在深入研究。
希望这可以帮助!