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:

NameDatatypeDescription
idstring (uint64)Output only. [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 withRFC1035. 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](?:[-a-z0-9]{0,61}[a-z0-9])?)
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, seeEnabling IP Forwarding.
confidentialInstanceConfigobjectA set of Confidential Instance options. (id: ConfidentialInstanceConfig)
cpuPlatformstringOutput only. [Output Only] The CPU platform used by this instance.
creationTimestampstringOutput only. [Output Only] Creation timestamp inRFC3339 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 acustomer-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. (KEY_REVOCATION_ACTION_TYPE_UNSPECIFIED, NONE, STOP)
kindstringOutput only. [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.
lastStartTimestampstringOutput only. [Output Only] Last start timestamp inRFC3339 text format.
lastStopTimestampstringOutput only. [Output Only] Last stop timestamp inRFC3339 text format.
lastSuspendedTimestampstringOutput only. [Output Only] Last suspended timestamp inRFC3339 text format.
localSsdEncryptionModestringSpecifies which method should be used for encrypting the Local SSDs attached to the VM. (EPHEMERAL_KEY_ENCRYPTION, LOCAL_SSD_ENCRYPTION_MODE_UNSPECIFIED, STANDARD_ENCRYPTION)
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 acustom 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 theSpecifications 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 aminimum 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. (ENABLE_BIDIRECTIONAL_ACCESS_TO_GOOGLE, ENABLE_OUTBOUND_VM_ACCESS_TO_GOOGLE, INHERIT_FROM_SUBNETWORK)
reservationAffinityobjectSpecifies the reservations that this instance can consume from. (id: ReservationAffinity)
resourcePoliciesarrayResource policies applied to this instance.
resourceStatusobjectOutput only. [Output Only] Specifies values set for instance attributes as compared to the values requested by user in the corresponding input only field. (id: ResourceStatus)
satisfiesPzibooleanOutput only. [Output Only] Reserved for future use.
satisfiesPzsbooleanOutput only. [Output Only] Reserved for future use.
schedulingobjectSets the scheduling options for this instance. (id: Scheduling)
selfLinkstringOutput only. [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. SeeService 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)
startRestrictedbooleanOutput only. [Output Only] Whether a VM has been restricted for start because Compute Engine has detected suspicious activity.
statusstringOutput only. [Output Only] The status of the instance. One of the following values: PROVISIONING, STAGING,RUNNING, STOPPING, SUSPENDING,SUSPENDED, REPAIRING, andTERMINATED. For more information about the status of the instance, see Instance life cycle. (DEPROVISIONING, PENDING, PENDING_STOP, PROVISIONING, REPAIRING, RUNNING, STAGING, STOPPED, STOPPING, SUSPENDED, SUSPENDING, TERMINATED)
statusMessagestringOutput only. [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 withRFC1035. Multiple tags can be specified via the 'tags.items' field. (id: Tags)
workloadIdentityConfigobject (id: WorkloadIdentityConfig)
zonestringOutput only. [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, zonemaxResults, pageToken, filter, orderBy, returnPartialSuccessRetrieves the list of instances contained within
the specified zone.
aggregated_listselectprojectreturnPartialSuccess, maxResults, pageToken, filter, serviceProjectNumber, includeAllScopes, orderByRetrieves 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, zonesourceInstanceTemplate, sourceMachineImage, requestIdCreates an instance resource in the specified project using the data
included in the request.
updatereplaceproject, zone, instancemostDisruptiveAllowedAction, requestId, minimalAction, discardLocalSsdUpdates 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, instancenoGracefulShutdown, requestIdDeletes the specified Instance resource. For more information, seeDeleting
an instance.
bulk_insertexecproject, zonerequestIdCreates multiple instances. Count specifies the number of instances to
create. For more information, seeAbout bulk
creation of VMs.
set_machine_resourcesexecproject, zone, instancerequestIdChanges the number and/or type of accelerator for a stopped instance to the
values specified in the request.
set_tagsexecproject, zone, instancerequestIdSets network tags
for the specified instance to the data included in the request.
perform_maintenanceexecproject, zone, instancerequestIdPerform a manual maintenance on the instance.
set_schedulingexecproject, zone, instancerequestIdSets an instance's scheduling options. You can only call this method on astopped instance,
that is, a VM instance that is in a TERMINATED state. SeeInstance Life
Cycle for more information on the possible instance states.
For more information about setting scheduling options for a VM, seeSet
VM host maintenance policy.
set_labelsexecproject, zone, instancerequestIdSets labels on an instance. To learn more about labels, read theLabeling
Resources documentation.
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.
start_with_encryption_keyexecproject, zone, instancerequestIdStarts an instance that was stopped using theinstances().stop
method. For more information, seeRestart an
instance.
stopexecproject, zone, instancerequestId, noGracefulShutdown, discardLocalSsdStops 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, seeStopping
an instance.
report_host_as_faultyexecproject, zone, instancerequestIdMark the host as faulty and try to restart the instance on a new host.
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, readAdding a
persistent disk to your instance.
set_deletion_protectionexecproject, zone, resourcerequestId, deletionProtectionSets deletion protection on the instance.
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, readSpecifying a
Minimum CPU Platform.
set_service_accountexecproject, zone, instancerequestIdSets the service account on the instance. For more information,
readChanging
the service account and access scopes for an instance.
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_disk_auto_deleteexecproject, zone, instance, autoDelete, deviceNamerequestIdSets the auto-delete flag for a disk attached to an instance.
detach_diskexecproject, zone, instance, deviceNamerequestIdDetaches a disk from an instance.
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 supportsPATCH
semantics and uses theJSON merge
patch format and processing rules.
simulate_maintenance_eventexecproject, zone, instancerequestId, withExtendedNotificationsSimulates a host maintenance event on a VM. For more information, see
Simulate a host maintenance event.
startexecproject, zone, instancerequestIdStarts an instance that was stopped using theinstances().stop
method. For more information, seeRestart an
instance.
resumeexecproject, zone, instancerequestIdResumes an instance that was suspended using theinstances().suspend
method.
resetexecproject, zone, instancerequestIdPerforms a reset on the instance. This is a hard reset. The VM
does not do a graceful shutdown. For more information, seeResetting
an instance.
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 supportsPATCH
semantics and uses theJSON merge
patch format and processing rules.
set_machine_typeexecproject, zone, instancerequestIdChanges the machine type for a stopped instance to the machine
type specified in the request.
set_security_policyexecproject, zone, instancerequestIdSets the Google Cloud Armor security policy for the specified instance.
For more information, seeGoogle
Cloud Armor Overview
send_diagnostic_interruptexecproject, zone, instanceSends diagnostic interrupt to the instance.
set_nameexecproject, zone, instancerequestIdSets name of an 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.

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
resourcestring
zonestring
deletionProtectionboolean
discardLocalSsdboolean
filterstring
forceAttachboolean
includeAllScopesboolean
maxResultsinteger (uint32)
minimalActionstring
mostDisruptiveAllowedActionstring
noGracefulShutdownboolean
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,
localSsdEncryptionMode,
machineType,
metadata,
minCpuPlatform,
networkInterfaces,
networkPerformanceConfig,
params,
privateIpv6GoogleAccess,
reservationAffinity,
resourcePolicies,
resourceStatus,
satisfiesPzi,
satisfiesPzs,
scheduling,
selfLink,
serviceAccounts,
shieldedInstanceConfig,
shieldedInstanceIntegrityPolicy,
sourceMachineImage,
sourceMachineImageEncryptionKey,
startRestricted,
status,
statusMessage,
tags,
workloadIdentityConfig,
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__description,
data__disks,
data__metadata,
data__serviceAccounts,
data__keyRevocationActionType,
data__networkInterfaces,
data__name,
data__confidentialInstanceConfig,
data__displayDevice,
data__localSsdEncryptionMode,
data__resourcePolicies,
data__shieldedInstanceConfig,
data__reservationAffinity,
data__deletionProtection,
data__instanceEncryptionKey,
data__hostname,
data__labels,
data__advancedMachineFeatures,
data__sourceMachineImageEncryptionKey,
data__labelFingerprint,
data__workloadIdentityConfig,
data__params,
data__minCpuPlatform,
data__tags,
data__shieldedInstanceIntegrityPolicy,
data__canIpForward,
data__networkPerformanceConfig,
data__machineType,
data__sourceMachineImage,
data__fingerprint,
data__scheduling,
data__guestAccelerators,
data__privateIpv6GoogleAccess,
project,
zone,
sourceInstanceTemplate,
sourceMachineImage,
requestId
)
SELECT
'{{ description }}',
'{{ disks }}',
'{{ metadata }}',
'{{ serviceAccounts }}',
'{{ keyRevocationActionType }}',
'{{ networkInterfaces }}',
'{{ name }}',
'{{ confidentialInstanceConfig }}',
'{{ displayDevice }}',
'{{ localSsdEncryptionMode }}',
'{{ resourcePolicies }}',
'{{ shieldedInstanceConfig }}',
'{{ reservationAffinity }}',
{{ deletionProtection }},
'{{ instanceEncryptionKey }}',
'{{ hostname }}',
'{{ labels }}',
'{{ advancedMachineFeatures }}',
'{{ sourceMachineImageEncryptionKey }}',
'{{ labelFingerprint }}',
'{{ workloadIdentityConfig }}',
'{{ params }}',
'{{ minCpuPlatform }}',
'{{ tags }}',
'{{ shieldedInstanceIntegrityPolicy }}',
{{ canIpForward }},
'{{ networkPerformanceConfig }}',
'{{ machineType }}',
'{{ sourceMachineImage }}',
'{{ fingerprint }}',
'{{ scheduling }}',
'{{ guestAccelerators }}',
'{{ privateIpv6GoogleAccess }}',
'{{ project }}',
'{{ zone }}',
'{{ sourceInstanceTemplate }}',
'{{ sourceMachineImage }}',
'{{ requestId }}'
RETURNING
id,
name,
clientOperationId,
creationTimestamp,
description,
endTime,
error,
getVersionOperationMetadata,
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__description = '{{ description }}',
data__disks = '{{ disks }}',
data__metadata = '{{ metadata }}',
data__serviceAccounts = '{{ serviceAccounts }}',
data__keyRevocationActionType = '{{ keyRevocationActionType }}',
data__networkInterfaces = '{{ networkInterfaces }}',
data__name = '{{ name }}',
data__confidentialInstanceConfig = '{{ confidentialInstanceConfig }}',
data__displayDevice = '{{ displayDevice }}',
data__localSsdEncryptionMode = '{{ localSsdEncryptionMode }}',
data__resourcePolicies = '{{ resourcePolicies }}',
data__shieldedInstanceConfig = '{{ shieldedInstanceConfig }}',
data__reservationAffinity = '{{ reservationAffinity }}',
data__deletionProtection = {{ deletionProtection }},
data__instanceEncryptionKey = '{{ instanceEncryptionKey }}',
data__hostname = '{{ hostname }}',
data__labels = '{{ labels }}',
data__advancedMachineFeatures = '{{ advancedMachineFeatures }}',
data__sourceMachineImageEncryptionKey = '{{ sourceMachineImageEncryptionKey }}',
data__labelFingerprint = '{{ labelFingerprint }}',
data__workloadIdentityConfig = '{{ workloadIdentityConfig }}',
data__params = '{{ params }}',
data__minCpuPlatform = '{{ minCpuPlatform }}',
data__tags = '{{ tags }}',
data__shieldedInstanceIntegrityPolicy = '{{ shieldedInstanceIntegrityPolicy }}',
data__canIpForward = {{ canIpForward }},
data__networkPerformanceConfig = '{{ networkPerformanceConfig }}',
data__machineType = '{{ machineType }}',
data__sourceMachineImage = '{{ sourceMachineImage }}',
data__fingerprint = '{{ fingerprint }}',
data__scheduling = '{{ scheduling }}',
data__guestAccelerators = '{{ guestAccelerators }}',
data__privateIpv6GoogleAccess = '{{ privateIpv6GoogleAccess }}'
WHERE
project = '{{ project }}' --required
AND zone = '{{ zone }}' --required
AND instance = '{{ instance }}' --required
AND mostDisruptiveAllowedAction = '{{ mostDisruptiveAllowedAction}}'
AND requestId = '{{ requestId}}'
AND minimalAction = '{{ minimalAction}}'
AND discardLocalSsd = {{ discardLocalSsd}}
RETURNING
id,
name,
clientOperationId,
creationTimestamp,
description,
endTime,
error,
getVersionOperationMetadata,
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, seeDeleting
an instance.

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

Lifecycle Methods

Creates multiple instances. Count specifies the number of instances to
create. For more information, seeAbout bulk
creation of VMs.

EXEC google.compute.instances.bulk_insert
@project='{{ project }}' --required,
@zone='{{ zone }}' --required,
@requestId='{{ requestId }}'
@@json=
'{
"sourceInstanceTemplate": "{{ sourceInstanceTemplate }}",
"instanceProperties": "{{ instanceProperties }}",
"count": "{{ count }}",
"minCount": "{{ minCount }}",
"namePattern": "{{ namePattern }}",
"perInstanceProperties": "{{ perInstanceProperties }}",
"locationPolicy": "{{ locationPolicy }}",
"instanceFlexibilityPolicy": "{{ instanceFlexibilityPolicy }}"
}'
;