我的 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
对于您的第二个磁盘,您希望使用
disk = "sql-server-secondary"
而不是image
作为标识符。此外,最好使用 Terraform 的插值语法(例如${...}
)引用第二个磁盘,以确保以适当的顺序创建和管理您的资源。InitializeParams
来自预先存在的图像(代码)的磁盘的Terraform 集会导致您收到错误。在这种情况下似乎可能存在错误,从现有映像附加非启动磁盘,但我仍在深入研究。希望这可以帮助!