すべての Compute Engine コードサンプル

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

This page contains code samples for Compute Engine. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Add memory to an existing VM

Update a VM with extended memory per vCPU.

Change the auto-delete setting of a disk

Change the value of the auto-delete flag, which determines whether the disk attached to a VM is automatically deleted or not when you delete the VM.

Change the deletion protection setting for an existing VM

Enable deletion protection for an existing VM without stopping the VM.

View in documentation

Check operation status

Request to wait until an operation completes and get the operation status before continuing code execution.

View in documentation

Create a disk from a snapshot

Create a zonal disk from a snapshot.

Create a disk image

Create a disk image from a source disk and store it in a Cloud Storage location.

Create a disk snapshot

Create a zonal or a regional snapshot of a disk in the specified Cloud Storage location.

Create a firewall rule

Create a firewall rule that allows incoming HTTP and HTTPS access from the entire internet.

View in documentation

Create a preemptible VM

Use the specified network, machine type, and source image and create a preemptible VM.

View in documentation

Create a VM from a custom image

Use a custom image as the boot disk and create a VM.

View in documentation

Create a VM from existing disk

Create a disk from a snapshot and attach the disk to a new VM.

Create a VM instance

Create a VM instance in the specified project and zone.

Create a VM instance from an instance template

Use an instance template to create a VM instance in the specified project and zone.

Create a VM instance from an instance template with overrides

Create a VM instance from an instance template, then override the disk and machine type options in the template.

Create a VM with a custom hostname

Create a VM with a custom hostname that conforms to the RFC 1035 requirements for valid hostnames.

Create a VM with a custom machine type

Create a VM with the specified number of vCPUs and the specified amount of memory.

Create a VM with custom machine type and extended memory

Extend the amount of memory per vCPU and create a VM with that custom machine type.

Create a Windows Server image

Create a Windows Server image from the specified source disk.

View in documentation

Create a Windows Server VM with external IP address

Configure routes and firewall rules in your custom VPC network and create a Windows Server VM that has an external IP address.

View in documentation

Create a Windows Server VM with internal IP address

Configure routes, firewall rules, and subnets in your custom VPC network and create a Windows Server VM that has an internal IP address.

View in documentation

Create an instance template

Use the specified machine type, boot disk and network to create an instance template.

View in documentation

Create an instance template based on an existing instance

Use the configuration of an existing VM to create an instance template.

View in documentation

Create an instance template with a subnet

Create an instance template that uses a specified subnetwork.

View in documentation

Delete a disk

Delete a persistent disk from the specified zone.

Delete a disk image

Delete a disk image from the specified project.

View in documentation

Delete a disk snapshot

Delete a disk snapshot from the specified project.

Delete a firewall rule

Delete a firewall rule from a specified project.

View in documentation

Delete a VM instance

Delete an instance based on the project, zone, and instance name that you provide.

Delete an instance template

Delete an instance template from a specified project.

Enable deletion protection for a new VM

Create a VM in the specified project and zone with deletion protection enabled.

View in documentation

Get information about an instance template

Get the basic information and instance configuration defined in an instance template.

Get the deletion protection status of a VM

Determine whether deletion protection is enabled for a specified VM.

View in documentation

List all non-deprecated images in a project

Get a list of all non-deprecated images available in a specified project.

List firewall rules in a project

Get a list of all firewall rules defined in your project.

View in documentation

List instance templates in a project

Get a list of instance templates defined in a project.

List VM instances in a project

List instances in a project, either in one zone or across all zones.

View in documentation

Reset a VM instance

Reset a running VM instance to its initial state.

View in documentation

Resume a suspended VM

Resume a suspended VM in the specified project and zone.

View in documentation

Start a VM instance

Restart a stopped VM instance.

View in documentation

Start a VM with encrypted disks

Provide an encryption key and start a VM instance that has encrypted disks.

View in documentation

Stop a VM instance

Stop a running VM instance.

View in documentation

Suspend a running VM

Suspend a running VM in the specified project and zone.

View in documentation

Update a firewall rule

Modify the priority of a firewall rule.

View in documentation