Instance Args
Manages a VM instance resource within GCE. For more information see the official documentation and API.
Example Usage
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.serviceAccount.Account;
import com.pulumi.gcp.serviceAccount.AccountArgs;
import com.pulumi.gcp.compute.Instance;
import com.pulumi.gcp.compute.InstanceArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
import com.pulumi.gcp.compute.inputs.InstanceScratchDiskArgs;
import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
import com.pulumi.gcp.compute.inputs.InstanceServiceAccountArgs;
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) {
var defaultAccount = new Account("defaultAccount", AccountArgs.builder()
.accountId("service_account_id")
.displayName("Service Account")
.build());
var defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()
.machineType("e2-medium")
.zone("us-central1-a")
.tags(
"foo",
"bar")
.bootDisk(InstanceBootDiskArgs.builder()
.initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
.image("debian-cloud/debian-11")
.labels(Map.of("my_label", "value"))
.build())
.build())
.scratchDisks(InstanceScratchDiskArgs.builder()
.interface_("SCSI")
.build())
.networkInterfaces(InstanceNetworkInterfaceArgs.builder()
.network("default")
.accessConfigs()
.build())
.metadata(Map.of("foo", "bar"))
.metadataStartupScript("echo hi /test.txt")
.serviceAccount(InstanceServiceAccountArgs.builder()
.email(defaultAccount.email())
.scopes("cloud-platform")
.build())
.build());
}
}
Import
Instances can be imported using any of these accepted formats
$ pulumi import gcp:compute/instance:Instance default projects/{{project}}/zones/{{zone}}/instances/{{name}}
$ pulumi import gcp:compute/instance:Instance default {{project}}/{{zone}}/{{name}}
$ pulumi import gcp:compute/instance:Instance default {{name}}
custom-vm-typeshttps://cloud.google.com/dataproc/docs/concepts/compute/custom-machine-types network-tierhttps://cloud.google.com/network-tiers/docs/overview extended-custom-vm-typehttps://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#extendedmemory
Constructors
Properties
Configure Nested Virtualisation and Simultaneous Hyper Threading on this VM. Structure is documented below
If true, allows this prvider to stop the instance to update its properties. If you try to update a property that requires stopping the instance without setting this field, the update will fail.
Additional disks to attach to the instance. Can be repeated multiple times for multiple disks. Structure is documented below.
The boot disk for the instance. Structure is documented below.
Whether to allow sending and receiving of packets with non-matching source or destination IPs. This defaults to false.
Enable Confidential Mode on this VM. Structure is documented below
Enable deletion protection on this instance. Defaults to false. Note: you must disable deletion protection before removing the resource (e.g., via pulumi destroy
), or the instance cannot be deleted and the provider run will not complete successfully.
A brief description of this resource.
Desired status of the instance. Either "RUNNING"
or "TERMINATED"
.
Enable Virtual Displays on this instance. Note: allow_stopping_for_update
must be set to true or your instance must have a desired_status
of TERMINATED
in order to update this field.
List of the type and count of accelerator cards attached to the instance. Structure documented below. Note: GPU accelerators can only be used with on_host_maintenance
option set to TERMINATE.
A custom hostname for the instance. Must be a fully qualified DNS name and RFC-1035-valid. Valid format is a series of labels 1-63 characters long matching the regular expression a-z
, concatenated with periods. The entire hostname must not exceed 253 characters. Changing this forces a new resource to be created.
The machine type to create. Note: If you want to update this value (resize the VM) after initial creation, you must set allow_stopping_for_update
to true
. custom-vm-types can be formatted as custom-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY_MB
, e.g. custom-6-20480
for 6 vCPU and 20GB of RAM. There is a limit of 6.5 GB per CPU unless you add extended-custom-vm-type. You must do this explicitly by adding the suffix -ext
, e.g. custom-2-15360-ext
for 2 vCPU and 15 GB of memory.
Metadata key/value pairs to make available from within the instance. Ssh keys attached in the Cloud Console will be removed. Add them to your config in order to keep them attached to your instance. A list of default metadata values (e.g. ssh-keys) can be found here
An alternative to using the startup-script metadata key, except this one forces the instance to be recreated (thus re-running the script) if it is changed. This replaces the startup-script metadata key on the created instance and thus the two mechanisms are not allowed to be used simultaneously. Users are free to use either mechanism - the only distinction is that this separate attribute will cause a recreate on modification. On import, metadata_startup_script
will not be set - if you choose to specify it you will see a diff immediately after import causing a destroy/recreate operation. If importing an instance and specifying this value is desired, you will need to modify your state file.
Specifies a minimum CPU platform for the VM instance. Applicable values are the friendly names of CPU platforms, such as Intel Haswell
or Intel Skylake
. See the complete list here. Note: allow_stopping_for_update
must be set to true or your instance must have a desired_status
of TERMINATED
in order to update this field.
Networks to attach to the instance. This can be specified multiple times. Structure is documented below.
Configures network performance settings for the instance. Structure is documented below. Note: machine_type
must be a supported type, the image
used must include the GVNIC
in guest-os-features
, and network_interface.0.nic-type
must be GVNIC
in order for this setting to take effect.
Additional instance parameters. .
Specifies the reservations that this instance can consume from. Structure is documented below.
The scheduling strategy to use. More details about this configuration option are detailed below.
Scratch disks to attach to the instance. This can be specified multiple times for multiple scratch disks. Structure is documented below.
Service account to attach to the instance. Structure is documented below. Note: allow_stopping_for_update
must be set to true or your instance must have a desired_status
of TERMINATED
in order to update this field.
Enable Shielded VM on this instance. Shielded VM provides verifiable integrity to prevent against malware and rootkits. Defaults to disabled. Structure is documented below. Note: shielded_instance_config
can only be used with boot images with shielded vm support. See the complete list here. Note: allow_stopping_for_update
must be set to true or your instance must have a desired_status
of TERMINATED
in order to update this field.