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
Property-Based Availability
Create a VM instance template for each machine type with 16GB of memory and 8 CPUs available in the provided zone.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as std from "@pulumi/std";
export = async () => {
const example = await gcp.compute.getMachineTypes({
filter: "memoryMb = 16384 AND guestCpus = 8",
zone: zone,
});
const exampleInstanceTemplate: gcp.compute.InstanceTemplate[] = [];
for (const range of std.toset({
input: example.machineTypes.map(__item => __item.name),
}).result.map((v, k) => ({key: k, value: v}))) {
exampleInstanceTemplate.push(new gcp.compute.InstanceTemplate(`example-${range.key}`, {
machineType: range.value,
disks: [{
sourceImage: "debian-cloud/debian-11",
autoDelete: true,
boot: true,
}],
}));
}
}
import pulumi
import pulumi_gcp as gcp
import pulumi_std as std
example = gcp.compute.get_machine_types(filter="memoryMb = 16384 AND guestCpus = 8",
zone=zone)
example_instance_template = []
for range in [{"key": k, "value": v} for [k, v] in enumerate(std.toset(input=[__item.name for __item in example.machine_types]).result)]:
example_instance_template.append(gcp.compute.InstanceTemplate(f"example-{range['key']}",
machine_type=range["value"],
disks=[{
"source_image": "debian-cloud/debian-11",
"auto_delete": True,
"boot": True,
}]))
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := compute.GetMachineTypes(ctx, &compute.GetMachineTypesArgs{
Filter: pulumi.StringRef("memoryMb = 16384 AND guestCpus = 8"),
Zone: pulumi.StringRef(zone),
}, nil);
if err != nil {
return err
}
var exampleInstanceTemplate []*compute.InstanceTemplate
for key0, val0 := range interface{}(std.Toset(ctx, &std.TosetArgs{
Input: %!v(PANIC=Format method: fatal: A failure has occurred: unlowered splat expression @ example.pp:9,15-43),
}, nil).Result) {
__res, err := compute.NewInstanceTemplate(ctx, fmt.Sprintf("example-%v", key0), &compute.InstanceTemplateArgs{
MachineType: pulumi.Any(val0),
Disks: compute.InstanceTemplateDiskArray{
&compute.InstanceTemplateDiskArgs{
SourceImage: pulumi.String("debian-cloud/debian-11"),
AutoDelete: pulumi.Bool(true),
Boot: pulumi.Bool(true),
},
},
})
if err != nil {
return err
}
exampleInstanceTemplate = append(exampleInstanceTemplate, __res)
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Pulumi;
using Gcp = Pulumi.Gcp;
using Std = Pulumi.Std;
return await Deployment.RunAsync(async() =>
{
var example = await Gcp.Compute.GetMachineTypes.InvokeAsync(new()
{
Filter = "memoryMb = 16384 AND guestCpus = 8",
Zone = zone,
});
var exampleInstanceTemplate = new List<Gcp.Compute.InstanceTemplate>();
foreach (var range in )
{
exampleInstanceTemplate.Add(new Gcp.Compute.InstanceTemplate($"example-{range.Key}", new()
{
MachineType = range.Value,
Disks = new[]
{
new Gcp.Compute.Inputs.InstanceTemplateDiskArgs
{
SourceImage = "debian-cloud/debian-11",
AutoDelete = true,
Boot = true,
},
},
}));
}
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetMachineTypesArgs;
import com.pulumi.gcp.compute.InstanceTemplate;
import com.pulumi.gcp.compute.InstanceTemplateArgs;
import com.pulumi.gcp.compute.inputs.InstanceTemplateDiskArgs;
import com.pulumi.codegen.internal.KeyedValue;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var example = ComputeFunctions.getMachineTypes(GetMachineTypesArgs.builder()
.filter("memoryMb = 16384 AND guestCpus = 8")
.zone(zone)
.build());
for (var range : KeyedValue.of(com.pulumi.std.StdFunctions(TosetArgs.builder()
.input(example.machineTypes().stream().map(element -> element.name()).collect(toList()))
.build()).result())) {
new InstanceTemplate("exampleInstanceTemplate-" + range.key(), InstanceTemplateArgs.builder()
.machineType(range.value())
.disks(InstanceTemplateDiskArgs.builder()
.sourceImage("debian-cloud/debian-11")
.autoDelete(true)
.boot(true)
.build())
.build());
}
}
}
resources:
exampleInstanceTemplate:
type: gcp:compute:InstanceTemplate
name: example
properties:
machineType: ${range.value}
disks:
- sourceImage: debian-cloud/debian-11
autoDelete: true
boot: true
options: {}
variables:
example:
fn::invoke:
function: gcp:compute:getMachineTypes
arguments:
filter: memoryMb = 16384 AND guestCpus = 8
zone: ${zone}
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.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as std from "@pulumi/std";
const example = gcp.compute.getMachineTypes({
filter: "memoryMb = 16384 AND guestCpus = 4",
zone: zone,
});
const exampleInstanceTemplate = new gcp.compute.InstanceTemplate("example", {
machineType: Promise.all([example, std.startswith({
input: mt.name,
prefix: "c3-",
}), example, std.startswith({
input: mt.name,
prefix: "c2-",
}), example, std.startswith({
input: mt.name,
prefix: "n2-",
})]).then(([example, invoke, example1, invoke1, example2, invoke2]) => std.coalescelist({
input: [
.filter(mt => invoke.result).map(mt => (mt.name)),
.filter(mt => invoke1.result).map(mt => (mt.name)),
.filter(mt => invoke2.result).map(mt => (mt.name)),
],
})).then(invoke => invoke.result?.[0]),
disks: [{
sourceImage: "debian-cloud/debian-11",
autoDelete: true,
boot: true,
}],
});
import pulumi
import pulumi_gcp as gcp
import pulumi_std as std
example = gcp.compute.get_machine_types(filter="memoryMb = 16384 AND guestCpus = 4",
zone=zone)
example_instance_template = gcp.compute.InstanceTemplate("example",
machine_type=std.coalescelist(input=[
[mt.name for mt in example.machine_types if std.startswith(input=mt.name,
prefix="c3-").result],
[mt.name for mt in example.machine_types if std.startswith(input=mt.name,
prefix="c2-").result],
[mt.name for mt in example.machine_types if std.startswith(input=mt.name,
prefix="n2-").result],
]).result[0],
disks=[{
"source_image": "debian-cloud/debian-11",
"auto_delete": True,
"boot": True,
}])
Example coming soon!
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var example = Gcp.Compute.GetMachineTypes.Invoke(new()
{
Filter = "memoryMb = 16384 AND guestCpus = 4",
Zone = zone,
});
var exampleInstanceTemplate = new Gcp.Compute.InstanceTemplate("example", new()
{
MachineType = Output.Tuple(example, Std.Startswith.Invoke(new()
{
Input = mt.Name,
Prefix = "c3-",
}), example, Std.Startswith.Invoke(new()
{
Input = mt.Name,
Prefix = "c2-",
}), example, Std.Startswith.Invoke(new()
{
Input = mt.Name,
Prefix = "n2-",
})).Apply(values =>
{
var example = values.Item1;
var invoke = values.Item2;
var example1 = values.Item3;
var invoke1 = values.Item4;
var example2 = values.Item5;
var invoke2 = values.Item6;
return Std.Coalescelist.Invoke(new()
{
Input = new[]
{
.Where(mt => invoke.Result).Select(mt =>
{
return mt.Name;
}).ToList(),
.Where(mt => invoke1.Result).Select(mt =>
{
return mt.Name;
}).ToList(),
.Where(mt => invoke2.Result).Select(mt =>
{
return mt.Name;
}).ToList(),
},
});
}).Apply(invoke => invoke.Result[0]),
Disks = new[]
{
new Gcp.Compute.Inputs.InstanceTemplateDiskArgs
{
SourceImage = "debian-cloud/debian-11",
AutoDelete = true,
Boot = true,
},
},
});
});
Example coming soon!
Example coming soon!
Using getMachineTypes
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getMachineTypes(args: GetMachineTypesArgs, opts?: InvokeOptions): Promise<GetMachineTypesResult>
function getMachineTypesOutput(args: GetMachineTypesOutputArgs, opts?: InvokeOptions): Output<GetMachineTypesResult>def get_machine_types(filter: Optional[str] = None,
project: Optional[str] = None,
zone: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetMachineTypesResult
def get_machine_types_output(filter: Optional[pulumi.Input[str]] = None,
project: Optional[pulumi.Input[str]] = None,
zone: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetMachineTypesResult]func GetMachineTypes(ctx *Context, args *GetMachineTypesArgs, opts ...InvokeOption) (*GetMachineTypesResult, error)
func GetMachineTypesOutput(ctx *Context, args *GetMachineTypesOutputArgs, opts ...InvokeOption) GetMachineTypesResultOutput> Note: This function is named GetMachineTypes in the Go SDK.
public static class GetMachineTypes
{
public static Task<GetMachineTypesResult> InvokeAsync(GetMachineTypesArgs args, InvokeOptions? opts = null)
public static Output<GetMachineTypesResult> Invoke(GetMachineTypesInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetMachineTypesResult> getMachineTypes(GetMachineTypesArgs args, InvokeOptions options)
public static Output<GetMachineTypesResult> getMachineTypes(GetMachineTypesArgs args, InvokeOptions options)
fn::invoke:
function: gcp:compute/getMachineTypes:getMachineTypes
arguments:
# arguments dictionaryThe following arguments are supported:
getMachineTypes Result
The following output properties are available:
- Id string
- The provider-assigned unique ID for this managed resource.
- Machine
Types List<GetMachine Types Machine Type> - The list of machine types matching the provided filter. Structure is documented below.
- Project string
- Zone string
- Filter string
- Id string
- The provider-assigned unique ID for this managed resource.
- Machine
Types []GetMachine Types Machine Type - The list of machine types matching the provided filter. Structure is documented below.
- Project string
- Zone string
- Filter string
- id String
- The provider-assigned unique ID for this managed resource.
- machine
Types List<GetMachine Types Machine Type> - The list of machine types matching the provided filter. Structure is documented below.
- project String
- zone String
- filter String
- id string
- The provider-assigned unique ID for this managed resource.
- machine
Types GetMachine Types Machine Type[] - The list of machine types matching the provided filter. Structure is documented below.
- project string
- zone string
- filter string
- id str
- The provider-assigned unique ID for this managed resource.
- machine_
types Sequence[GetMachine Types Machine Type] - The list of machine types matching the provided filter. Structure is documented below.
- project str
- zone str
- filter str
- id String
- The provider-assigned unique ID for this managed resource.
- machine
Types List<Property Map> - The list of machine types matching the provided filter. Structure is documented below.
- project String
- zone String
- filter String
Supporting Types
GetMachineTypesMachineType
- Accelerators
List<Get
Machine Types Machine Type Accelerator> - A list of accelerator configurations assigned to this machine type. Structure is documented below.
- Bundled
Local List<GetSsds Machine Types Machine Type Bundled Local Ssd> - The configuration of bundled local SSD for the machine type. Structure is documented below.
- Deprecateds
List<Get
Machine Types Machine Type Deprecated> - The deprecation status associated with this machine type. Structure is documented below.
- Description string
- A textual description of the machine type.
- Guest
Cpus int - The number of virtual CPUs that are available to the instance.
- bool
- Whether this machine type has a shared CPU.
- Maximum
Persistent intDisks - The maximum persistent disks allowed.
- Maximum
Persistent intDisks Size Gb - The maximum total persistent disks size (GB) allowed.
- Memory
Mb int - The amount of physical memory available to the instance, defined in MB.
- Name string
- The name of the machine type.
- Self
Link string - The server-defined URL for the machine type.
- Accelerators
[]Get
Machine Types Machine Type Accelerator - A list of accelerator configurations assigned to this machine type. Structure is documented below.
- Bundled
Local []GetSsds Machine Types Machine Type Bundled Local Ssd - The configuration of bundled local SSD for the machine type. Structure is documented below.
- Deprecateds
[]Get
Machine Types Machine Type Deprecated - The deprecation status associated with this machine type. Structure is documented below.
- Description string
- A textual description of the machine type.
- Guest
Cpus int - The number of virtual CPUs that are available to the instance.
- bool
- Whether this machine type has a shared CPU.
- Maximum
Persistent intDisks - The maximum persistent disks allowed.
- Maximum
Persistent intDisks Size Gb - The maximum total persistent disks size (GB) allowed.
- Memory
Mb int - The amount of physical memory available to the instance, defined in MB.
- Name string
- The name of the machine type.
- Self
Link string - The server-defined URL for the machine type.
- accelerators
List<Get
Machine Types Machine Type Accelerator> - A list of accelerator configurations assigned to this machine type. Structure is documented below.
- bundled
Local List<GetSsds Machine Types Machine Type Bundled Local Ssd> - The configuration of bundled local SSD for the machine type. Structure is documented below.
- deprecateds
List<Get
Machine Types Machine Type Deprecated> - The deprecation status associated with this machine type. Structure is documented below.
- description String
- A textual description of the machine type.
- guest
Cpus Integer - The number of virtual CPUs that are available to the instance.
- Boolean
- Whether this machine type has a shared CPU.
- maximum
Persistent IntegerDisks - The maximum persistent disks allowed.
- maximum
Persistent IntegerDisks Size Gb - The maximum total persistent disks size (GB) allowed.
- memory
Mb Integer - The amount of physical memory available to the instance, defined in MB.
- name String
- The name of the machine type.
- self
Link String - The server-defined URL for the machine type.
- accelerators
Get
Machine Types Machine Type Accelerator[] - A list of accelerator configurations assigned to this machine type. Structure is documented below.
- bundled
Local GetSsds Machine Types Machine Type Bundled Local Ssd[] - The configuration of bundled local SSD for the machine type. Structure is documented below.
- deprecateds
Get
Machine Types Machine Type Deprecated[] - The deprecation status associated with this machine type. Structure is documented below.
- description string
- A textual description of the machine type.
- guest
Cpus number - The number of virtual CPUs that are available to the instance.
- boolean
- Whether this machine type has a shared CPU.
- maximum
Persistent numberDisks - The maximum persistent disks allowed.
- maximum
Persistent numberDisks Size Gb - The maximum total persistent disks size (GB) allowed.
- memory
Mb number - The amount of physical memory available to the instance, defined in MB.
- name string
- The name of the machine type.
- self
Link string - The server-defined URL for the machine type.
- accelerators
Sequence[Get
Machine Types Machine Type Accelerator] - A list of accelerator configurations assigned to this machine type. Structure is documented below.
- bundled_
local_ Sequence[Getssds Machine Types Machine Type Bundled Local Ssd] - The configuration of bundled local SSD for the machine type. Structure is documented below.
- deprecateds
Sequence[Get
Machine Types Machine Type Deprecated] - The deprecation status associated with this machine type. Structure is documented below.
- description str
- A textual description of the machine type.
- guest_
cpus int - The number of virtual CPUs that are available to the instance.
- bool
- Whether this machine type has a shared CPU.
- maximum_
persistent_ intdisks - The maximum persistent disks allowed.
- maximum_
persistent_ intdisks_ size_ gb - The maximum total persistent disks size (GB) allowed.
- memory_
mb int - The amount of physical memory available to the instance, defined in MB.
- name str
- The name of the machine type.
- self_
link str - The server-defined URL for the machine type.
- accelerators List<Property Map>
- A list of accelerator configurations assigned to this machine type. Structure is documented below.
- bundled
Local List<Property Map>Ssds - The configuration of bundled local SSD for the machine type. Structure is documented below.
- deprecateds List<Property Map>
- The deprecation status associated with this machine type. Structure is documented below.
- description String
- A textual description of the machine type.
- guest
Cpus Number - The number of virtual CPUs that are available to the instance.
- Boolean
- Whether this machine type has a shared CPU.
- maximum
Persistent NumberDisks - The maximum persistent disks allowed.
- maximum
Persistent NumberDisks Size Gb - The maximum total persistent disks size (GB) allowed.
- memory
Mb Number - The amount of physical memory available to the instance, defined in MB.
- name String
- The name of the machine type.
- self
Link String - The server-defined URL for the machine type.
GetMachineTypesMachineTypeAccelerator
- Guest
Accelerator intCount - Number of accelerator cards exposed to the guest.
- Guest
Accelerator stringType - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
- Guest
Accelerator intCount - Number of accelerator cards exposed to the guest.
- Guest
Accelerator stringType - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
- guest
Accelerator IntegerCount - Number of accelerator cards exposed to the guest.
- guest
Accelerator StringType - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
- guest
Accelerator numberCount - Number of accelerator cards exposed to the guest.
- guest
Accelerator stringType - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
- guest_
accelerator_ intcount - Number of accelerator cards exposed to the guest.
- guest_
accelerator_ strtype - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
- guest
Accelerator NumberCount - Number of accelerator cards exposed to the guest.
- guest
Accelerator StringType - The accelerator type resource name, not a full URL, e.g.
nvidia-tesla-t4.
GetMachineTypesMachineTypeBundledLocalSsd
- Default
Interface string - The default disk interface if the interface is not specified.
- Partition
Count int - The number of partitions.
- Default
Interface string - The default disk interface if the interface is not specified.
- Partition
Count int - The number of partitions.
- default
Interface String - The default disk interface if the interface is not specified.
- partition
Count Integer - The number of partitions.
- default
Interface string - The default disk interface if the interface is not specified.
- partition
Count number - The number of partitions.
- default_
interface str - The default disk interface if the interface is not specified.
- partition_
count int - The number of partitions.
- default
Interface String - The default disk interface if the interface is not specified.
- partition
Count Number - The number of partitions.
GetMachineTypesMachineTypeDeprecated
- Replacement string
- The URL of the suggested replacement for a deprecated machine type.
- State string
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
- Replacement string
- The URL of the suggested replacement for a deprecated machine type.
- State string
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
- replacement String
- The URL of the suggested replacement for a deprecated machine type.
- state String
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
- replacement string
- The URL of the suggested replacement for a deprecated machine type.
- state string
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
- replacement str
- The URL of the suggested replacement for a deprecated machine type.
- state str
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
- replacement String
- The URL of the suggested replacement for a deprecated machine type.
- state String
- The deprecation state of this resource. This can be
ACTIVE,DEPRECATED,OBSOLETE, orDELETED.
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
google-betaTerraform Provider.
