Objective: I would like to have the list of the snapshosts archived for one Google GCE Instance then display the list of candidates. So easy in CLI, but cannot find in TF because data does not accept multiple records
Gcloud CLI - Linux function
listme () {
gcloud compute snapshots list --filter=“(name ~ $1)” --format=“csvno-heading”
}
Cmd sample : listme dev1gcesimcmaxdcdb4342
Output :
dev1gcesimcmaxdcdb4342-0,288
dev1gcesimcmaxdcdb4342-1,288
dev1gcesimcmaxdcdb4342-2,288
dev1gcesimcmaxdcdb4342-dump,296
dev1gcesimcmaxdcdb4342-temp,600
TF :
cat get.tf
data “google_compute_snapshot” “instance_snapshot” {
filter = “name:${var.instance_name}*”
}
output “instance_snapshot” {
description = “Snapshot name ans shapshot origin of the GCE instance”
value = data.google_compute_snapshot.instance_snapshot.*.name
}
terraform apply -auto-approve
data.google_compute_snapshot.instance_snapshot: Reading…
╷
│ Error: your filter has returned 5 snapshot(s). Please refine your filter or set most_recent to return exactly one snapshot
│
│ with data.google_compute_snapshot.instance_snapshot,
│ on get.tf line 2, in data “google_compute_snapshot” “instance_snapshot”:
│ 2: data “google_compute_snapshot” “instance_snapshot” {
│
╵
How to do such simple thing with TF ?
Thanks in advance