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:
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
}
}
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
}
}
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
}
}
The following arguments are supported:
filter
(Required) - A filter expression that filters machine types listed in the response.
zone
(Required) - Zone from which to list machine types.
project
(Optional) - Project from which to list available zones. Defaults to project declared in the provider.
The following attributes are exported:
machine_types
- The list of machine types matching the provided filter. Structure is documented below.The machine_types
block supports:
name
- The name of the machine type.
description
- A textual description of the machine type.
bundled_local_ssds
- (Beta) The configuration of bundled local SSD for the machine type. Structure is documented below.
deprecated
- The deprecation status associated with this machine type. Structure is documented below.
guest_cpus
- The number of virtual CPUs that are available to the instance.
memory_mb
- The amount of physical memory available to the instance, defined in MB.
maximum_persistent_disks
- The maximum persistent disks allowed.
maximum_persistent_disks_size_gb
- The maximum total persistent disks size (GB) allowed.
is_shared_cpus
- Whether this machine type has a shared CPU.
accelerators
- A list of accelerator configurations assigned to this machine type. Structure is documented below.
self_link
- The server-defined URL for the machine type.
The bundled_local_ssds
block supports:
default_interface
- (Beta) The default disk interface if the interface is not specified.
partition_count
- (Beta) The number of partitions.
The deprecated
block supports:
replacement
- The URL of the suggested replacement for a deprecated machine type.
state
- The deprecation state of this resource. This can be ACTIVE
, DEPRECATED
, OBSOLETE
, or DELETED
.
The accelerators
block supports:
guest_accelerator_type
- The accelerator type resource name, not a full URL, e.g. nvidia-tesla-t4
.
guest_accelerator_count
- Number of accelerator cards exposed to the guest.