Skip to main content

instances

Creates, updates, deletes, gets or lists an instances resource.

Overview

Nameinstances
TypeResource
Idgoogle.compute.instances

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
idstring (uint64)[Output Only] The unique identifier for the resource. This identifier is defined by the server.
namestringThe name of the resource, provided by the client when initially creating the resource. The resource name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. (pattern: a-z?)
advancedMachineFeaturesobjectControls for advanced machine-related behavior features. (id: AdvancedMachineFeatures)
canIpForwardbooleanAllows this instance to send and receive packets with non-matching destination or source IPs. This is required if you plan to use this instance to forward routes. For more information, see Enabling IP Forwarding .
confidentialInstanceConfigobjectA set of Confidential Instance options. (id: ConfidentialInstanceConfig)
cpuPlatformstring[Output Only] The CPU platform used by this instance.
creationTimestampstring[Output Only] Creation timestamp in RFC3339 text format.
deletionProtectionbooleanWhether the resource should be protected against deletion.
descriptionstringAn optional description of this resource. Provide this property when you create the resource.
disksarrayArray of disks associated with this instance. Persistent disks must be created before you can assign them.
displayDeviceobjectEnables display device for the instance. (id: DisplayDevice)
fingerprintstring (byte)Specifies a fingerprint for this resource, which is essentially a hash of the instance's contents and used for optimistic locking. The fingerprint is initially generated by Compute Engine and changes after every request to modify or update the instance. You must always provide an up-to-date fingerprint hash in order to update the instance. To see the latest fingerprint, make get() request to the instance.
guestAcceleratorsarrayA list of the type and count of accelerator cards attached to the instance.
hostnamestringSpecifies the hostname of the instance. The specified hostname must be RFC1035 compliant. If hostname is not specified, the default hostname is [INSTANCE_NAME].c.[PROJECT_ID].internal when using the global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal when using zonal DNS.
instanceEncryptionKeyobjectEncrypts suspended data for an instance with a customer-managed encryption key. If you are creating a new instance, this field will encrypt the local SSD and in-memory contents of the instance during the suspend operation. If you do not provide an encryption key when creating the instance, then the local SSD and in-memory contents will be encrypted using an automatically generated key during the suspend operation. (id: CustomerEncryptionKey)
keyRevocationActionTypestringKeyRevocationActionType of the instance. Supported options are "STOP" and "NONE". The default value is "NONE" if it is not specified.
kindstring[Output Only] Type of the resource. Always compute#instance for instances. (default: compute#instance)
labelFingerprintstring (byte)A fingerprint for this request, which is essentially a hash of the label's contents and used for optimistic locking. The fingerprint is initially generated by Compute Engine and changes after every request to modify or update labels. You must always provide an up-to-date fingerprint hash in order to update or change labels. To see the latest fingerprint, make get() request to the instance.
labelsobjectLabels to apply to this instance. These can be later modified by the setLabels method.
lastStartTimestampstring[Output Only] Last start timestamp in RFC3339 text format.
lastStopTimestampstring[Output Only] Last stop timestamp in RFC3339 text format.
lastSuspendedTimestampstring[Output Only] Last suspended timestamp in RFC3339 text format.
machineTypestringFull or partial URL of the machine type resource to use for this instance, in the format: zones/zone/machineTypes/machine-type. This is provided by the client when the instance is created. For example, the following is a valid partial url to a predefined machine type: zones/us-central1-f/machineTypes/n1-standard-1 To create a custom machine type, provide a URL to a machine type in the following format, where CPUS is 1 or an even number up to 32 (2, 4, 6, ... 24, etc), and MEMORY is the total memory for this instance. Memory must be a multiple of 256 MB and must be supplied in MB (e.g. 5 GB of memory is 5120 MB): zones/zone/machineTypes/custom-CPUS-MEMORY For example: zones/us-central1-f/machineTypes/custom-4-5120 For a full list of restrictions, read the Specifications for custom machine types.
metadataobjectThe metadata key/value pairs assigned to this instance. This includes metadata keys that were explicitly defined for the instance. (id: Metadata)
minCpuPlatformstringSpecifies a minimum CPU platform for the VM instance. Applicable values are the friendly names of CPU platforms, such as minCpuPlatform: "Intel Haswell" or minCpuPlatform: "Intel Sandy Bridge".
networkInterfacesarrayAn array of network configurations for this instance. These specify how interfaces are configured to interact with other network services, such as connecting to the internet. Multiple interfaces are supported per instance.
networkPerformanceConfigobject (id: NetworkPerformanceConfig)
paramsobjectInput only. [Input Only] Additional params passed with the request, but not persisted as part of resource payload. (id: InstanceParams)
privateIpv6GoogleAccessstringThe private IPv6 google access type for the VM. If not specified, use INHERIT_FROM_SUBNETWORK as default.
reservationAffinityobjectSpecifies the reservations that this instance can consume from. (id: ReservationAffinity)
resourcePoliciesarrayResource policies applied to this instance.
resourceStatusobject[Output Only] Specifies values set for instance attributes as compared to the values requested by user in the corresponding input only field. (id: ResourceStatus)
satisfiesPziboolean[Output Only] Reserved for future use.
satisfiesPzsboolean[Output Only] Reserved for future use.
schedulingobjectSets the scheduling options for this instance. (id: Scheduling)
selfLinkstring[Output Only] Server-defined URL for this resource.
serviceAccountsarrayA list of service accounts, with their specified scopes, authorized for this instance. Only one service account per VM instance is supported. Service accounts generate access tokens that can be accessed through the metadata server and used to authenticate applications on the instance. See Service Accounts for more information.
shieldedInstanceConfigobjectA set of Shielded Instance options. (id: ShieldedInstanceConfig)
shieldedInstanceIntegrityPolicyobjectThe policy describes the baseline against which Instance boot integrity is measured. (id: ShieldedInstanceIntegrityPolicy)
sourceMachineImagestringSource machine image
sourceMachineImageEncryptionKeyobjectSource machine image encryption key when creating an instance from a machine image. (id: CustomerEncryptionKey)
startRestrictedboolean[Output Only] Whether a VM has been restricted for start because Compute Engine has detected suspicious activity.
statusstring[Output Only] The status of the instance. One of the following values: PROVISIONING, STAGING, RUNNING, STOPPING, SUSPENDING, SUSPENDED, REPAIRING, and TERMINATED. For more information about the status of the instance, see Instance life cycle.
statusMessagestring[Output Only] An optional, human-readable explanation of the status.
tagsobjectTags to apply to this instance. Tags are used to identify valid sources or targets for network firewalls and are specified by the client during instance creation. The tags can be later modified by the setTags method. Each tag within the list must comply with RFC1035. Multiple tags can be specified via the 'tags.items' field. (id: Tags)
zonestring[Output Only] URL of the zone where the instance resides. You must specify this field as part of the HTTP request URL. It is not settable as a field in the request body.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectproject, zone, instanceReturns the specified Instance resource.
listselectproject, zonefilter, maxResults, orderBy, pageToken, returnPartialSuccessRetrieves the list of instances contained within the specified zone.
aggregated_listselectprojectfilter, includeAllScopes, maxResults, orderBy, pageToken, returnPartialSuccess, serviceProjectNumberRetrieves an aggregated list of all of the instances in your project across all regions and zones. The performance of this method degrades when a filter is specified on a project that has a very large number of instances. To prevent failure, Google recommends that you set the returnPartialSuccess parameter to true.
insertinsertproject, zonerequestId, sourceInstanceTemplate, sourceMachineImageCreates an instance resource in the specified project using the data included in the request.
updatereplaceproject, zone, instanceminimalAction, mostDisruptiveAllowedAction, requestIdUpdates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties.
deletedeleteproject, zone, instancerequestIdDeletes the specified Instance resource. For more information, see Deleting an instance.
resetexecproject, zone, instancerequestIdPerforms a reset on the instance. This is a hard reset. The VM does not do a graceful shutdown. For more information, see Resetting an instance.
simulate_maintenance_eventexecproject, zone, instancerequestId, withExtendedNotificationsSimulates a host maintenance event on a VM. For more information, see Simulate a host maintenance event.
perform_maintenanceexecproject, zone, instancerequestIdPerform a manual maintenance on the instance.
report_host_as_faultyexecproject, zone, instancerequestIdMark the host as faulty and try to restart the instance on a new host.
update_network_interfaceexecproject, zone, instance, networkInterfacerequestIdUpdates an instance's network interface. This method can only update an interface's alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics.
set_schedulingexecproject, zone, instancerequestIdSets an instance's scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. For more information about setting scheduling options for a VM, see Set VM host maintenance policy.
send_diagnostic_interruptexecproject, zone, instanceSends diagnostic interrupt to the instance.
attach_diskexecproject, zone, instanceforceAttach, requestIdAttaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance.
detach_diskexecproject, zone, instance, deviceNamerequestIdDetaches a disk from an instance.
set_machine_resourcesexecproject, zone, instancerequestIdChanges the number and/or type of accelerator for a stopped instance to the values specified in the request.
set_machine_typeexecproject, zone, instancerequestIdChanges the machine type for a stopped instance to the machine type specified in the request.
set_metadataexecproject, zone, instancerequestIdSets metadata for the specified instance to the data included in the request.
set_min_cpu_platformexecproject, zone, instancerequestIdChanges the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform.
set_tagsexecproject, zone, instancerequestIdSets network tags for the specified instance to the data included in the request.
set_labelsexecproject, zone, instancerequestIdSets labels on an instance. To learn more about labels, read the Labeling Resources documentation.
set_nameexecproject, zone, instancerequestIdSets name of an instance.
set_disk_auto_deleteexecproject, zone, instance, autoDelete, deviceNamerequestIdSets the auto-delete flag for a disk attached to an instance.
startexecproject, zone, instancerequestIdStarts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
start_with_encryption_keyexecproject, zone, instancerequestIdStarts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
stopexecproject, zone, instancediscardLocalSsd, requestIdStops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, see Stopping an instance.
set_service_accountexecproject, zone, instancerequestIdSets the service account on the instance. For more information, read Changing the service account and access scopes for an instance.
set_deletion_protectionexecproject, zone, resourcedeletionProtection, requestIdSets deletion protection on the instance.
suspendexecproject, zone, instancediscardLocalSsd, requestIdThis method suspends a running instance, saving its state to persistent storage, and allows you to resume the instance at a later time. Suspended instances have no compute costs (cores or RAM), and incur only storage charges for the saved VM memory and localSSD data. Any charged resources the virtual machine was using, such as persistent disks and static IP addresses, will continue to be charged while the instance is suspended. For more information, see Suspending and resuming an instance.
resumeexecproject, zone, instancerequestIdResumes an instance that was suspended using the instances().suspend method.
update_shielded_instance_configexecproject, zone, instancerequestIdUpdates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
update_display_deviceexecproject, zone, instancerequestIdUpdates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
set_shielded_instance_integrity_policyexecproject, zone, instancerequestIdSets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
set_security_policyexecproject, zone, instancerequestIdSets the Google Cloud Armor security policy for the specified instance. For more information, see Google Cloud Armor Overview
bulk_insertexecproject, regionrequestIdCreates multiple instances in a given region. Count specifies the number of instances to create.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
autoDeleteboolean
deviceNamestring
instancestring
networkInterfacestring
projectstring
regionstring
resourcestring
zonestring
deletionProtectionboolean
discardLocalSsdboolean
filterstring
forceAttachboolean
includeAllScopesboolean
maxResultsinteger (uint32)
minimalActionstring
mostDisruptiveAllowedActionstring
orderBystring
pageTokenstring
requestIdstring
returnPartialSuccessboolean
serviceProjectNumberstring (int64)
sourceInstanceTemplatestring
sourceMachineImagestring
withExtendedNotificationsboolean

SELECT examples

Returns the specified Instance resource.

SELECT
id,
name,
advancedMachineFeatures,
canIpForward,
confidentialInstanceConfig,
cpuPlatform,
creationTimestamp,
deletionProtection,
description,
disks,
displayDevice,
fingerprint,
guestAccelerators,
hostname,
instanceEncryptionKey,
keyRevocationActionType,
kind,
labelFingerprint,
labels,
lastStartTimestamp,
lastStopTimestamp,
lastSuspendedTimestamp,
machineType,
metadata,
minCpuPlatform,
networkInterfaces,
networkPerformanceConfig,
params,
privateIpv6GoogleAccess,
reservationAffinity,
resourcePolicies,
resourceStatus,
satisfiesPzi,
satisfiesPzs,
scheduling,
selfLink,
serviceAccounts,
shieldedInstanceConfig,
shieldedInstanceIntegrityPolicy,
sourceMachineImage,
sourceMachineImageEncryptionKey,
startRestricted,
status,
statusMessage,
tags,
zone
FROM google.compute.instances
WHERE project = '{{ project }}' -- required
AND zone = '{{ zone }}' -- required
AND instance = '{{ instance }}' -- required;

INSERT examples

Creates an instance resource in the specified project using the data included in the request.

INSERT INTO google.compute.instances (
data__kind,
data__id,
data__creationTimestamp,
data__name,
data__description,
data__tags,
data__machineType,
data__status,
data__statusMessage,
data__zone,
data__canIpForward,
data__networkInterfaces,
data__disks,
data__metadata,
data__serviceAccounts,
data__selfLink,
data__scheduling,
data__cpuPlatform,
data__labels,
data__params,
data__labelFingerprint,
data__instanceEncryptionKey,
data__minCpuPlatform,
data__guestAccelerators,
data__startRestricted,
data__deletionProtection,
data__resourcePolicies,
data__sourceMachineImage,
data__reservationAffinity,
data__hostname,
data__displayDevice,
data__shieldedInstanceConfig,
data__shieldedInstanceIntegrityPolicy,
data__sourceMachineImageEncryptionKey,
data__confidentialInstanceConfig,
data__fingerprint,
data__privateIpv6GoogleAccess,
data__advancedMachineFeatures,
data__lastStartTimestamp,
data__lastStopTimestamp,
data__lastSuspendedTimestamp,
data__satisfiesPzs,
data__satisfiesPzi,
data__resourceStatus,
data__networkPerformanceConfig,
data__keyRevocationActionType,
project,
zone,
requestId,
sourceInstanceTemplate,
sourceMachineImage
)
SELECT
'{{ kind }}',
'{{ id }}',
'{{ creationTimestamp }}',
'{{ name }}',
'{{ description }}',
'{{ tags }}',
'{{ machineType }}',
'{{ status }}',
'{{ statusMessage }}',
'{{ zone }}',
{{ canIpForward }},
'{{ networkInterfaces }}',
'{{ disks }}',
'{{ metadata }}',
'{{ serviceAccounts }}',
'{{ selfLink }}',
'{{ scheduling }}',
'{{ cpuPlatform }}',
'{{ labels }}',
'{{ params }}',
'{{ labelFingerprint }}',
'{{ instanceEncryptionKey }}',
'{{ minCpuPlatform }}',
'{{ guestAccelerators }}',
{{ startRestricted }},
{{ deletionProtection }},
'{{ resourcePolicies }}',
'{{ sourceMachineImage }}',
'{{ reservationAffinity }}',
'{{ hostname }}',
'{{ displayDevice }}',
'{{ shieldedInstanceConfig }}',
'{{ shieldedInstanceIntegrityPolicy }}',
'{{ sourceMachineImageEncryptionKey }}',
'{{ confidentialInstanceConfig }}',
'{{ fingerprint }}',
'{{ privateIpv6GoogleAccess }}',
'{{ advancedMachineFeatures }}',
'{{ lastStartTimestamp }}',
'{{ lastStopTimestamp }}',
'{{ lastSuspendedTimestamp }}',
{{ satisfiesPzs }},
{{ satisfiesPzi }},
'{{ resourceStatus }}',
'{{ networkPerformanceConfig }}',
'{{ keyRevocationActionType }}',
'{{ project }}',
'{{ zone }}',
'{{ requestId }}',
'{{ sourceInstanceTemplate }}',
'{{ sourceMachineImage }}'
RETURNING
id,
name,
clientOperationId,
creationTimestamp,
description,
endTime,
error,
httpErrorMessage,
httpErrorStatusCode,
insertTime,
instancesBulkInsertOperationMetadata,
kind,
operationGroupId,
operationType,
progress,
region,
selfLink,
setCommonInstanceMetadataOperationMetadata,
startTime,
status,
statusMessage,
targetId,
targetLink,
user,
warnings,
zone
;

REPLACE examples

Updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties.

REPLACE google.compute.instances
SET
data__kind = '{{ kind }}',
data__id = '{{ id }}',
data__creationTimestamp = '{{ creationTimestamp }}',
data__name = '{{ name }}',
data__description = '{{ description }}',
data__tags = '{{ tags }}',
data__machineType = '{{ machineType }}',
data__status = '{{ status }}',
data__statusMessage = '{{ statusMessage }}',
data__zone = '{{ zone }}',
data__canIpForward = {{ canIpForward }},
data__networkInterfaces = '{{ networkInterfaces }}',
data__disks = '{{ disks }}',
data__metadata = '{{ metadata }}',
data__serviceAccounts = '{{ serviceAccounts }}',
data__selfLink = '{{ selfLink }}',
data__scheduling = '{{ scheduling }}',
data__cpuPlatform = '{{ cpuPlatform }}',
data__labels = '{{ labels }}',
data__params = '{{ params }}',
data__labelFingerprint = '{{ labelFingerprint }}',
data__instanceEncryptionKey = '{{ instanceEncryptionKey }}',
data__minCpuPlatform = '{{ minCpuPlatform }}',
data__guestAccelerators = '{{ guestAccelerators }}',
data__startRestricted = {{ startRestricted }},
data__deletionProtection = {{ deletionProtection }},
data__resourcePolicies = '{{ resourcePolicies }}',
data__sourceMachineImage = '{{ sourceMachineImage }}',
data__reservationAffinity = '{{ reservationAffinity }}',
data__hostname = '{{ hostname }}',
data__displayDevice = '{{ displayDevice }}',
data__shieldedInstanceConfig = '{{ shieldedInstanceConfig }}',
data__shieldedInstanceIntegrityPolicy = '{{ shieldedInstanceIntegrityPolicy }}',
data__sourceMachineImageEncryptionKey = '{{ sourceMachineImageEncryptionKey }}',
data__confidentialInstanceConfig = '{{ confidentialInstanceConfig }}',
data__fingerprint = '{{ fingerprint }}',
data__privateIpv6GoogleAccess = '{{ privateIpv6GoogleAccess }}',
data__advancedMachineFeatures = '{{ advancedMachineFeatures }}',
data__lastStartTimestamp = '{{ lastStartTimestamp }}',
data__lastStopTimestamp = '{{ lastStopTimestamp }}',
data__lastSuspendedTimestamp = '{{ lastSuspendedTimestamp }}',
data__satisfiesPzs = {{ satisfiesPzs }},
data__satisfiesPzi = {{ satisfiesPzi }},
data__resourceStatus = '{{ resourceStatus }}',
data__networkPerformanceConfig = '{{ networkPerformanceConfig }}',
data__keyRevocationActionType = '{{ keyRevocationActionType }}'
WHERE
project = '{{ project }}' --required
AND zone = '{{ zone }}' --required
AND instance = '{{ instance }}' --required
AND minimalAction = '{{ minimalAction}}'
AND mostDisruptiveAllowedAction = '{{ mostDisruptiveAllowedAction}}'
AND requestId = '{{ requestId}}'
RETURNING
id,
name,
clientOperationId,
creationTimestamp,
description,
endTime,
error,
httpErrorMessage,
httpErrorStatusCode,
insertTime,
instancesBulkInsertOperationMetadata,
kind,
operationGroupId,
operationType,
progress,
region,
selfLink,
setCommonInstanceMetadataOperationMetadata,
startTime,
status,
statusMessage,
targetId,
targetLink,
user,
warnings,
zone;

DELETE examples

Deletes the specified Instance resource. For more information, see Deleting an instance.

DELETE FROM google.compute.instances
WHERE project = '{{ project }}' --required
AND zone = '{{ zone }}' --required
AND instance = '{{ instance }}' --required
AND requestId = '{{ requestId }}';

Lifecycle Methods

Performs a reset on the instance. This is a hard reset. The VM does not do a graceful shutdown. For more information, see Resetting an instance.

EXEC google.compute.instances.reset 
@project='{{ project }}' --required,
@zone='{{ zone }}' --required,
@instance='{{ instance }}' --required,
@requestId='{{ requestId }}';