【发布时间】:2018-01-31 22:37:29
【问题描述】:
我知道这可以通过控制台实现,但是,如何从 terraform 中的另一个项目初始化引导磁盘映像?
这是我目前所拥有的,但它表示找不到图像:
boot_disk {
initialize_params {
image = "cof-ubuntu1604-180124"
}
}
【问题讨论】:
标签: google-cloud-platform terraform
我知道这可以通过控制台实现,但是,如何从 terraform 中的另一个项目初始化引导磁盘映像?
这是我目前所拥有的,但它表示找不到图像:
boot_disk {
initialize_params {
image = "cof-ubuntu1604-180124"
}
}
【问题讨论】:
标签: google-cloud-platform terraform
您在“图像”字段中使用的磁盘地址不正确。
首先你需要确保你可以从你的项目中访问图片,见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
【讨论】:
图片不是图片名,是图片的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}"
}
}
...
}
参考:
【讨论】:
提供的答案都非常有帮助并解决了我的问题。 API Explorer 的使用对于确定正确的 URI 非常重要。
【讨论】: