How do I create a VM instance in GCP with the latest snapshot using Terraform?

455 views
Skip to first unread message

Eric Mwaura

unread,
Apr 29, 2021, 10:04:17 AM4/29/21
to gce-discussion

know I  have to first create a compute_disk , then reference the snapshot I want to use; however since snapshots are constantly updated, how would I make sure that terraform is using the most recent snapshot to create the Instance?

Digil (Google Cloud Platform Support)

unread,
May 3, 2021, 11:35:59 AM5/3/21
to gce-discussion
By using the orderBy="creationTimestamp desc"  while listing the snapshots, it should gives you a lists of snapshots in reverse chronological order (newest result first). So before creating the GCE VM using terraform, you need to decide the snapshot with the help of orderBy="creationTimestamp desc"  query parameter. I am not sure how this logic can be included in your terraform script, but I believe you could find a solution by posting the concern in 'Terraform's community support' forums.

Kumar Dhanagopal

unread,
May 4, 2021, 1:14:03 PM5/4/21
to gce-discussion
To do this in Terraform, we would need a data source to retrieve a list of snapshots for a given source disk. Such a data source doesn't exist, though it's been requested: https://github.com/hashicorp/terraform-provider-google/issues/3382 .
Reply all
Reply to author
Forward
0 new messages