我知道这可以通过控制台实现,但是,如何从terraform中的另一个项目初始化启动盘映像?
这是我到目前为止所得到的,但它说它无法找到图像:
boot_disk {
initialize_params {
image = "cof-ubuntu1604-180124"
}
}
答案 0 :(得分:1)
您没有在字段" image"上使用正确的磁盘地址。
首先,您需要确保可以访问项目中的图片,请参阅here for info about sharing images
然后,"图像"您正在使用的变量必须指向正确的URI。它看起来像这样:
"selfLink": "projects/ndjanuary-190908/global/images/ffs12354",
您可以使用方法" compute.images.get"从Compute Engine API获取该信息。我的请求看起来像这样:
GET https://www.googleapis.com/compute/v1/projects/ndjanuary-190908/global/images/ffs12354?key={YOUR_API_KEY}
以下是相关API资源管理器的链接:
https://developers.google.com/apis-explorer/#search/image/m/compute/v1/compute.images.get
答案 1 :(得分:0)
图像不是图像名称,而是图像的URI。
data "google_compute_image" "my_image" {
name = "cof-ubuntu1604-180124"
# could also use family = "family-name"
}
resource "google_compute_instance" "default" {
name = "test"
...
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
...
}
参考:
答案 2 :(得分:0)
The answers provided were bOth very helpful and solved my issues. THe use of the API Explorer was invaluable to fining the correct URI.