This is an update from Headless Linux with Google Compute Engine Desktop

Main Idea: reduce cost of persistent disk with automatic deployment from a snapshot with Terraform.

On my previous setup, the cost of the persistent disk was 7⁄ 7 24⁄ 24 , even when the VM was turned down.

Cost are :

HDD: $0.040 Go/Mo

SSD: $0.170

Snapshot: $0.026

Snapshot cost the real size, persistent disk cost what you choose. This mean you can setup a 50Go SSD for performence purpose, and store as a real 23.7Go for exemple once stores as a snapshot. It’s save money if you dont use your workstation for a couple of days. If you have a light version of a desktop manager, it could be very cheap storage, with only few Go.

This can be done if the launch of the VM is fast enough, and worth the few bucks saved. To launch the VM, it takes about 1 minute. It’s up to you if this minute worth some money to you.

I’m launching it directly from the cloud shell as terraform is already installed.

This will create a persistent disk from the snapshot (see below a script that will generate it), create a VM and attach the disk to it.

Note: a good idea would be to have two disk, one for data, and one for the OS (next post on a setup in azure for a windows workstation setup)

Note2: i’m using a preemptible VM that cost around 5 time less than the real one.

mkdir ubuntu vim ubuntu.tf resource "google_compute_disk" "persistent" { name = "home-disk" type = "pd-ssd" zone = "europe-west1-b" size = 30 physical_block_size_bytes = 4096 snapshot = "ubuntu-gnome" } resource "google_compute_instance" "default" { name = "home5" machine_type = "n2-standard-16" zone = "europe-west1-b" boot_disk { source = google_compute_disk.persistent.name } network_interface { network = "default" } service_account { scopes = [ "userinfo-email" , "compute-ro" , "storage-ro" ] } scheduling { preemptible = true automatic_restart = false } }

Once this is done launch it !

terraform init # only the first time terraform apply

Here’s my snapshot.sh, I first turn down the VM, save data like this on the snaphot

gcloud compute snapshots delete ubuntu-gnome gcloud compute disks snapshot home-disk --zone=europe-west1-b --snapshot-names=ubuntu-gnome

Once the snapshot done, you want release all resources like this

terraform destroy

Done, everything is removed, VM, CPU, RAM, Persistent Disk. You just have the cost effective snapshot left.

I’ve done almost the same thing for a windows workstation, with 2 disks on Azure. Blog post is comming soon!