Terraform a Google Compute instance with openSUSE Leap 15

May 6, 2019
Linux openSUSE DevOps HashiCorp

I’ve been fiddling with HashiCorp’s Terraform and the Google Compute Platform (GCP) lately. When creating a compute instance using the gcloud CLI tool I was a bit disappointed not to find openSUSE images.

$ gcloud compute images list

Luckily, a little patience reading the Google Compute Engine documentation bore the fruit. openSUSE Leap images are “community images” that are not directly supported by Google Compute Engine. Therefore, openSUSE Leap images are available under the opensuse-cloud project.

$ gcloud compute images list --project opensuse-cloud --no-standard-images
NAME                          PROJECT         FAMILY         DEPRECATED  STATUS
opensuse-leap-15-v20181106    opensuse-cloud  opensuse-leap              READY
opensuse-leap-42-3-v20180116  opensuse-cloud  opensuse-leap              READY

The --no-standard-images flag disables the --standard-images flag which is enabled by default. Specifying this flag prevents the listing of all images from well-known projects such as debian-cloud, rhel-cloud, suse-cloud etc and displays results from opensuse-cloud only.

Terraform Logo

Now that we know where to find the openSUSE Leap image, we can create a compute instance with the following Terraform config.

resource "google_compute_instance" "opensuse-testing" {
    name = "opensuse-testing"
    machine_type = "f1-micro"
    zone = "europe-west4-a"
    tags = ["testing"]

    boot_disk {
        initialize_params {
            image = "opensuse-cloud/opensuse-leap"
            size = 10
            type = "pd-ssd"
        }
    }

    metadata_startup_script = "zypper up"

    network_interface {
        network = "default"

        access_config {
            // Ephemeral IP
        }
    }
}

Logos are property of their respective owners.

https://github.com/openSUSE/artwork/tree/master/logos/official
https://www.terraform.io/logos.html