Reputation: 1325
I have some working code that creates snapshots of disks attached to an existing server in GCP:
provider "google" {
credentials = file("mycreds.json")
project = var.project
region = var.region
}
data "google_compute_image" "sqlserverimage" {
family = var.image_family
project = var.project
}
data "google_compute_instance" "sql_instance" {
name = var.instance_name
project = var.project
zone = var.zone
}
output "instance" {
value = data.google_compute_instance.sql_instance
}
//Create boot disk snapshot
resource "google_compute_snapshot" "boot_snapshot" {
name = var.boot_snapshot_name
source_disk = var.boot_disk_name
zone = var.zone
storage_locations = [var.region]
}
But now I want to restore the snapshots to new volumes. I've been googling around and I haven't found any answers that pertain to GCP.
How can I restore the snapshots I take using Terraform into a new volume?
Upvotes: 1
Views: 1067
Reputation: 26
I think you could try to create the new VM within the snapshot that you have created for the old VM.
First, you need to create a google_compute_disk
with the snapshot that you had created, using the snapshot parameter
Then should create the VM with the compute_instance
module, with the bootDisk.source with the previous disk created
Upvotes: 1