Google cloud platform Terraform按名称和时间戳检索最新的GCE图像

Google cloud platform Terraform按名称和时间戳检索最新的GCE图像,google-cloud-platform,terraform,google-compute-engine,gcloud,Google Cloud Platform,Terraform,Google Compute Engine,Gcloud,我在谷歌云上有多张图像,格式如下: test-${creationTimestamp} 我可以使用gcloud轻松检索最新图像: gcloud compute images list --filter=name=test --limit=1 --sort-by=~creationTimestamp 这是我能做的最大限度: data "google_compute_image" "my_image" { filter = "(name=t

我在谷歌云上有多张图像,格式如下:

test-${creationTimestamp}
我可以使用gcloud轻松检索最新图像:

gcloud compute images list --filter=name=test --limit=1 --sort-by=~creationTimestamp

这是我能做的最大限度:

data "google_compute_image" "my_image" {
  filter = "(name=test)"
}
它将返回多个,这意味着它无法工作:

Error: your filter has returned more than one image or no image. Please refine your filter to return exactly one image

你知道不使用gcloud如何实现这一点吗?

你有没有理由不能用
系列创建图像,然后用它来选择系列中最新的图像?我误解了带有图像名称的source\u image\u系列,我不知道我可以给图像系列指定一个自定义名称,这意味着你建议的方法确实有效。谢谢大家!@ydaetskcoR(你可以创建一个答案,如果你愿意,我会接受)有什么原因你不能用
族创建图像,然后用它来选择族中最新的图像吗?我误解了源图像族和图像族的名称,我不知道我可以给图像族一个自定义名称,这意味着你的建议起了作用。谢谢大家!@ydaetskcoR(您可以创建一个答案,如果您愿意,我将接受)