InstanceArgs

data class InstanceArgs(val advancedMachineFeatures: Output<InstanceAdvancedMachineFeaturesArgs>? = null, val allowStoppingForUpdate: Output<Boolean>? = null, val attachedDisks: Output<List<InstanceAttachedDiskArgs>>? = null, val bootDisk: Output<InstanceBootDiskArgs>? = null, val canIpForward: Output<Boolean>? = null, val confidentialInstanceConfig: Output<InstanceConfidentialInstanceConfigArgs>? = null, val deletionProtection: Output<Boolean>? = null, val description: Output<String>? = null, val desiredStatus: Output<String>? = null, val enableDisplay: Output<Boolean>? = null, val guestAccelerators: Output<List<InstanceGuestAcceleratorArgs>>? = null, val hostname: Output<String>? = null, val labels: Output<Map<String, String>>? = null, val machineType: Output<String>? = null, val metadata: Output<Map<String, String>>? = null, val metadataStartupScript: Output<String>? = null, val minCpuPlatform: Output<String>? = null, val name: Output<String>? = null, val networkInterfaces: Output<List<InstanceNetworkInterfaceArgs>>? = null, val networkPerformanceConfig: Output<InstanceNetworkPerformanceConfigArgs>? = null, val params: Output<InstanceParamsArgs>? = null, val partnerMetadata: Output<Map<String, String>>? = null, val project: Output<String>? = null, val reservationAffinity: Output<InstanceReservationAffinityArgs>? = null, val resourcePolicies: Output<String>? = null, val scheduling: Output<InstanceSchedulingArgs>? = null, val scratchDisks: Output<List<InstanceScratchDiskArgs>>? = null, val serviceAccount: Output<InstanceServiceAccountArgs>? = null, val shieldedInstanceConfig: Output<InstanceShieldedInstanceConfigArgs>? = null, val tags: Output<List<String>>? = null, val zone: Output<String>? = null) : ConvertibleToJava<InstanceArgs>

Manages a VM instance resource within GCE. For more information see the official documentation and API.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const _default = new gcp.serviceaccount.Account("default", {
accountId: "my-custom-sa",
displayName: "Custom SA for VM Instance",
});
const defaultInstance = new gcp.compute.Instance("default", {
networkInterfaces: [{
accessConfigs: [{}],
network: "default",
}],
name: "my-instance",
machineType: "n2-standard-2",
zone: "us-central1-a",
tags: [
"foo",
"bar",
],
bootDisk: {
initializeParams: {
image: "debian-cloud/debian-11",
labels: {
my_label: "value",
},
},
},
scratchDisks: [{
"interface": "NVME",
}],
metadata: {
foo: "bar",
},
metadataStartupScript: "echo hi /test.txt",
serviceAccount: {
email: _default.email,
scopes: ["cloud-platform"],
},
});
import pulumi
import pulumi_gcp as gcp
default = gcp.serviceaccount.Account("default",
account_id="my-custom-sa",
display_name="Custom SA for VM Instance")
default_instance = gcp.compute.Instance("default",
network_interfaces=[{
"access_configs": [{}],
"network": "default",
}],
name="my-instance",
machine_type="n2-standard-2",
zone="us-central1-a",
tags=[
"foo",
"bar",
],
boot_disk={
"initialize_params": {
"image": "debian-cloud/debian-11",
"labels": {
"my_label": "value",
},
},
},
scratch_disks=[{
"interface": "NVME",
}],
metadata={
"foo": "bar",
},
metadata_startup_script="echo hi /test.txt",
service_account={
"email": default.email,
"scopes": ["cloud-platform"],
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var @default = new Gcp.ServiceAccount.Account("default", new()
{
AccountId = "my-custom-sa",
DisplayName = "Custom SA for VM Instance",
});
var defaultInstance = new Gcp.Compute.Instance("default", new()
{
NetworkInterfaces = new[]
{
new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
{
AccessConfigs = new[]
{
null,
},
Network = "default",
},
},
Name = "my-instance",
MachineType = "n2-standard-2",
Zone = "us-central1-a",
Tags = new[]
{
"foo",
"bar",
},
BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
{
InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
{
Image = "debian-cloud/debian-11",
Labels =
{
{ "my_label", "value" },
},
},
},
ScratchDisks = new[]
{
new Gcp.Compute.Inputs.InstanceScratchDiskArgs
{
Interface = "NVME",
},
},
Metadata =
{
{ "foo", "bar" },
},
MetadataStartupScript = "echo hi /test.txt",
ServiceAccount = new Gcp.Compute.Inputs.InstanceServiceAccountArgs
{
Email = @default.Email,
Scopes = new[]
{
"cloud-platform",
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := serviceaccount.NewAccount(ctx, "default", &serviceaccount.AccountArgs{
AccountId: pulumi.String("my-custom-sa"),
DisplayName: pulumi.String("Custom SA for VM Instance"),
})
if err != nil {
return err
}
_, err = compute.NewInstance(ctx, "default", &compute.InstanceArgs{
NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
&compute.InstanceNetworkInterfaceArgs{
AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
nil,
},
Network: pulumi.String("default"),
},
},
Name: pulumi.String("my-instance"),
MachineType: pulumi.String("n2-standard-2"),
Zone: pulumi.String("us-central1-a"),
Tags: pulumi.StringArray{
pulumi.String("foo"),
pulumi.String("bar"),
},
BootDisk: &compute.InstanceBootDiskArgs{
InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
Image: pulumi.String("debian-cloud/debian-11"),
Labels: pulumi.StringMap{
"my_label": pulumi.String("value"),
},
},
},
ScratchDisks: compute.InstanceScratchDiskArray{
&compute.InstanceScratchDiskArgs{
Interface: pulumi.String("NVME"),
},
},
Metadata: pulumi.StringMap{
"foo": pulumi.String("bar"),
},
MetadataStartupScript: pulumi.String("echo hi /test.txt"),
ServiceAccount: &compute.InstanceServiceAccountArgs{
Email: _default.Email,
Scopes: pulumi.StringArray{
pulumi.String("cloud-platform"),
},
},
})
if err != nil {
return err
}
return nil
})
}
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.InstanceNetworkInterfaceArgs;
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.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 default_ = new Account("default", AccountArgs.builder()
.accountId("my-custom-sa")
.displayName("Custom SA for VM Instance")
.build());
var defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()
.networkInterfaces(InstanceNetworkInterfaceArgs.builder()
.accessConfigs()
.network("default")
.build())
.name("my-instance")
.machineType("n2-standard-2")
.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_("NVME")
.build())
.metadata(Map.of("foo", "bar"))
.metadataStartupScript("echo hi /test.txt")
.serviceAccount(InstanceServiceAccountArgs.builder()
.email(default_.email())
.scopes("cloud-platform")
.build())
.build());
}
}
resources:
default:
type: gcp:serviceaccount:Account
properties:
accountId: my-custom-sa
displayName: Custom SA for VM Instance
defaultInstance:
type: gcp:compute:Instance
name: default
properties:
networkInterfaces:
- accessConfigs:
- {}
network: default
name: my-instance
machineType: n2-standard-2
zone: us-central1-a
tags:
- foo
- bar
bootDisk:
initializeParams:
image: debian-cloud/debian-11
labels:
my_label: value
scratchDisks:
- interface: NVME
metadata:
foo: bar
metadataStartupScript: echo hi /test.txt
serviceAccount:
email: ${default.email}
scopes:
- cloud-platform

Import

Instances can be imported using any of these accepted formats:

  • projects/{{project}}/zones/{{zone}}/instances/{{name}}

  • {{project}}/{{zone}}/{{name}}

  • {{name}} When using the pulumi import command, instances can be imported using one of the formats above. For example:

$ 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}}

Constructors

Link copied to clipboard
constructor(advancedMachineFeatures: Output<InstanceAdvancedMachineFeaturesArgs>? = null, allowStoppingForUpdate: Output<Boolean>? = null, attachedDisks: Output<List<InstanceAttachedDiskArgs>>? = null, bootDisk: Output<InstanceBootDiskArgs>? = null, canIpForward: Output<Boolean>? = null, confidentialInstanceConfig: Output<InstanceConfidentialInstanceConfigArgs>? = null, deletionProtection: Output<Boolean>? = null, description: Output<String>? = null, desiredStatus: Output<String>? = null, enableDisplay: Output<Boolean>? = null, guestAccelerators: Output<List<InstanceGuestAcceleratorArgs>>? = null, hostname: Output<String>? = null, labels: Output<Map<String, String>>? = null, machineType: Output<String>? = null, metadata: Output<Map<String, String>>? = null, metadataStartupScript: Output<String>? = null, minCpuPlatform: Output<String>? = null, name: Output<String>? = null, networkInterfaces: Output<List<InstanceNetworkInterfaceArgs>>? = null, networkPerformanceConfig: Output<InstanceNetworkPerformanceConfigArgs>? = null, params: Output<InstanceParamsArgs>? = null, partnerMetadata: Output<Map<String, String>>? = null, project: Output<String>? = null, reservationAffinity: Output<InstanceReservationAffinityArgs>? = null, resourcePolicies: Output<String>? = null, scheduling: Output<InstanceSchedulingArgs>? = null, scratchDisks: Output<List<InstanceScratchDiskArgs>>? = null, serviceAccount: Output<InstanceServiceAccountArgs>? = null, shieldedInstanceConfig: Output<InstanceShieldedInstanceConfigArgs>? = null, tags: Output<List<String>>? = null, zone: Output<String>? = null)

Properties

Link copied to clipboard

Configure Nested Virtualisation and Simultaneous Hyper Threading on this VM. Structure is documented below

Link copied to clipboard
val allowStoppingForUpdate: Output<Boolean>? = null

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.

Link copied to clipboard

Additional disks to attach to the instance. Can be repeated multiple times for multiple disks. Structure is documented below.

Link copied to clipboard
val bootDisk: Output<InstanceBootDiskArgs>? = null

The boot disk for the instance. Structure is documented below.

Link copied to clipboard
val canIpForward: Output<Boolean>? = null

Whether to allow sending and receiving of packets with non-matching source or destination IPs. This defaults to false.

Link copied to clipboard

Enable Confidential Mode on this VM. Structure is documented below

Link copied to clipboard
val deletionProtection: Output<Boolean>? = null

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.

Link copied to clipboard
val description: Output<String>? = null

A brief description of this resource.

Link copied to clipboard
val desiredStatus: Output<String>? = null

Desired status of the instance. Either "RUNNING" or "TERMINATED".

Link copied to clipboard
val enableDisplay: Output<Boolean>? = null

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.

Link copied to clipboard

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.

Link copied to clipboard
val hostname: Output<String>? = null

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.

Link copied to clipboard
val labels: Output<Map<String, String>>? = null

A map of key/value label pairs to assign to the instance. Note: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field 'effective_labels' for all of the labels present on the resource.

Link copied to clipboard
val machineType: Output<String>? = null

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 machine 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 memory. You must do this explicitly by adding the suffix -ext, e.g. custom-2-15360-ext for 2 vCPU and 15 GB of memory.

Link copied to clipboard
val metadata: Output<Map<String, String>>? = null

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 predefined metadata keys (e.g. ssh-keys) can be found here

Link copied to clipboard
val metadataStartupScript: Output<String>? = null

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.

Link copied to clipboard
val minCpuPlatform: Output<String>? = null

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.

Link copied to clipboard
val name: Output<String>? = null

A unique name for the resource, required by GCE. Changing this forces a new resource to be created.

Link copied to clipboard

Networks to attach to the instance. This can be specified multiple times. Structure is documented below.

Link copied to clipboard

(Optional, Beta 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.

Link copied to clipboard
val params: Output<InstanceParamsArgs>? = null

Additional instance parameters. .

Link copied to clipboard
val partnerMetadata: Output<Map<String, String>>? = null

Beta key/value pair represents partner metadata assigned to instance where key represent a defined namespace and value is a json string represent the entries associted with the namespace.

Link copied to clipboard
val project: Output<String>? = null

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Link copied to clipboard

Specifies the reservations that this instance can consume from. Structure is documented below.

Link copied to clipboard
val resourcePolicies: Output<String>? = null
Link copied to clipboard
val scheduling: Output<InstanceSchedulingArgs>? = null

The scheduling strategy to use. More details about this configuration option are detailed below.

Link copied to clipboard

Scratch disks to attach to the instance. This can be specified multiple times for multiple scratch disks. Structure is documented below.

Link copied to clipboard

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.

Link copied to clipboard

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.

Link copied to clipboard
val tags: Output<List<String>>? = null

A list of network tags to attach to the instance.

Link copied to clipboard
val zone: Output<String>? = null

The zone that the machine should be created in. If it is not provided, the provider zone is used.

Functions

Link copied to clipboard
open override fun toJava(): InstanceArgs