google_compute_machine_types

Provides access to available Google Compute machine types in a zone for a given project. See more about machine type availability in the upstream docs.

To get more information about machine types, see:

Example Usage - Machine Type properties

Configure a Google Kubernetes Engine (GKE) cluster with node auto-provisioning, using memory constraints matching the memory of the provided machine type.

data "google_compute_machine_types" "example" {
  filter = "name = \"n1-standard-1\""
  zone   = "us-central1-a"
}

resource "google_container_cluster" "example" {
  name = "my-gke-cluster"

  cluster_autoscaling {
    enabled = true
    resource_limits {
      resource_type = "memory"
      minimum       =  2 * data.google_compute_machine_types.example.machine_types[0].memory_mb
      maximum       =  4 * data.google_compute_machine_types.example.machine_types[0].memory_mb
    }
}

Example Usage - Property-based availability

Create a VM instance template for each machine type with 16GB of memory and 8 CPUs available in the provided zone.

data "google_compute_machine_types" "example" {
  filter = "memoryMb = 16384 AND guestCpus = 8"
  zone   = var.zone
}

resource "google_compute_instance_template" "example" {
  for_each     = toset(data.google_compute_machine_types.example.machine_types[*].name)
  machine_type = each.value

  disk {
    source_image = "debian-cloud/debian-11"
    auto_delete  = true
    boot         = true
  }
}

Example Usage - Machine Family preference

Create an instance template, preferring c3 machine family if available in the provided zone, otherwise falling back to c2 and finally n2.

data "google_compute_machine_types" "example" {
  filter = "memoryMb = 16384 AND guestCpus = 4"
  zone   = var.zone
}

resource "google_compute_instance_template" "example" {
  machine_type = coalescelist(
    [for mt in data.google_compute_machine_types.example.machine_types: mt.name if startswith(mt.name, "c3-")],
    [for mt in data.google_compute_machine_types.example.machine_types: mt.name if startswith(mt.name, "c2-")],
    [for mt in data.google_compute_machine_types.example.machine_types: mt.name if startswith(mt.name, "n2-")],
  )[0]

  disk {
    source_image = "debian-cloud/debian-11"
    auto_delete  = true
    boot         = true
  }
}

Argument Reference

The following arguments are supported:

Attributes Reference

The following attributes are exported:

The machine_types block supports:

The bundled_local_ssds block supports:

The deprecated block supports:

The accelerators block supports: