Compute Engine lets you create and run
[instances](https://docs.cloud.google.com/compute/docs/instances) on Google infrastructure.
This document shows how to create a Compute Engine instance.

The terms *Compute Engine instance*, *compute instance* or
*instance* are synonymous. Based on the
[machine type](https://docs.cloud.google.com/compute/docs/machine-resource)
that you specify, an instance can be either a bare metal instance
or a virtual machine (VM) instance, as follows:

- If the name of its machine type ends in `-metal`, an instance is a [bare metal instance](https://docs.cloud.google.com/compute/docs/machine-resource#bare-metal-types), which does not have a hypervisor installed.
- Otherwise, an instance is a VM instance. The terms *virtual machine instance*, *VM instance*, and *VM* are synonymous.

Synonymous terms are used interchangeably
across the documentation and Google Cloud interfaces such as the
[Google Cloud console](https://console.cloud.google.com/), the
[gcloud](https://docs.cloud.google.com/compute/docs/gcloud-compute) command-line tool,
and the [REST API](https://docs.cloud.google.com/compute/docs/reference/latest).

<br />

The instructions in this document only introduce you to instance creation and
provide a starting point for creating an instance. For detailed steps on how to
create instances with specific or complicated configurations, see instead the
[Create and start instances with specific configurations](https://docs.cloud.google.com/compute/docs/instances/create-start-instance#custom-vm-configuration-documents).

## Before you begin

- Review the basics about [creating instances](https://docs.cloud.google.com/compute/docs/instances/instance-creation-overview).
- If you haven't already, set up [authentication](https://docs.cloud.google.com/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:

  Select the tab for how you plan to use the samples on this page:

  ### Console


  When you use the Google Cloud console to access Google Cloud services and
  APIs, you don't need to set up authentication.

  ### gcloud

  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

     After installation,
     [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

     ```bash
     gcloud init
     ```


     If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

     > [!NOTE]
     > **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.

  2. [Set a default region and zone](https://docs.cloud.google.com/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).

  ### Terraform


  To use the Terraform samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### C#


  To use the .NET samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### Go


  To use the Go samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### Java


  To use the Java samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### Node.js


  To use the Node.js samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### PHP


  To use the PHP samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### Python


  To use the Python samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### Ruby


  To use the Ruby samples on this page in a local development environment, install and
  initialize the gcloud CLI, and then set up Application Default Credentials with
  your user credentials.
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

  3.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Set up authentication for a local development environment](https://docs.cloud.google.com/compute/docs/authentication#local-development).

  ### REST


  To use the REST API samples on this page in a local development environment, you use the
  credentials you provide to the gcloud CLI.
  1. [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Authenticate for using REST](https://docs.cloud.google.com/docs/authentication/rest)
  in the Google Cloud authentication documentation.

### Required roles


To get the permissions that
you need to create instances,

ask your administrator to grant you the
[Compute Instance Admin (v1)](https://docs.cloud.google.com/iam/docs/roles-permissions/compute#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`) IAM role on the project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).


This predefined role contains

the permissions required to create instances. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to create instances:

- `compute.instances.create` on the project
- To use a custom image to create the VM: `compute.images.useReadOnly` on the image
- To use a snapshot to create the VM: `compute.snapshots.useReadOnly` on the snapshot
- To use an instance template to create the VM: `compute.instanceTemplates.useReadOnly` on the instance template
- To specify a subnet for your VM: `compute.subnetworks.use` on the project or on the chosen subnet
- To specify a static IP address for the VM: `compute.addresses.use` on the project
- To assign an external IP address to the VM when using a VPC network: `compute.subnetworks.useExternalIp` on the project or on the chosen subnet
- To assign a [legacy network](https://docs.cloud.google.com/vpc/docs/legacy) to the VM: `compute.networks.use` on the project
- To assign an external IP address to the VM when using a legacy network: `compute.networks.useExternalIp` on the project
- To set VM instance metadata for the VM: `compute.instances.setMetadata` on the project
- To set tags for the VM: `compute.instances.setTags` on the VM
- To set labels for the VM: `compute.instances.setLabels` on the VM
- To set a service account for the VM to use: `compute.instances.setServiceAccount` on the VM
- To create a new disk for the VM: `compute.disks.create` on the project
- To attach an existing disk in read-only or read-write mode: `compute.disks.use` on the disk
- To attach an existing disk in read-only mode: `compute.disks.useReadOnly` on the disk


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Methods to create and start an instance

This section describes the basic methods that you can use to create and start
a Compute Engine instance. This procedure is intended for introductory
purposes only. For detailed steps on how to configure and create your
instances, see the
[Create and start instances with specific configurations](https://docs.cloud.google.com/compute/docs/instances/create-start-instance#custom-vm-configuration-documents)
section instead.

For beginners, Google recommends using the Google Cloud console, the
Google Cloud CLI, or the REST API. Review the following instructions to learn
the general process for creating an instance with each method. Optionally, you
can generate the code to create an instance for Google Cloud CLI, REST,
or Terraform by using the
**Equivalent code** button on the **Create an instance** page in the
Google Cloud console. Generating code can help you learn syntax and prevent errors.
Learn more about
[Google Cloud console features for Compute Engine](https://docs.cloud.google.com/compute/docs/console).

### Console

1. In the Google Cloud console, go to the **Create an instance** page.

   [Go to Create an instance](https://console.cloud.google.com/compute/instancesAdd)

   The **Create an instance** screen appears and displays the
   **Machine configuration** pane.
2. To configure instance properties, use the options in the navigation menu
   as follows.

   > [!TIP]
   > **Tip:** For a summary of the options in the navigation menu, see [Configuration options during instance creation](https://docs.cloud.google.com/compute/docs/instances/instance-creation-overview#new-instance-configuration-options).

   - To configure instance properties related to name, location, or machine
     configuration, click **Machine configuration** . In the
     **Machine configuration** pane that appears, specify values for the
     properties that you want to configure.

   - To configure instance properties related to boot disk, operating
     system (OS), and additional non-boot storage options, click
     **OS and storage** . In the **Operating system and storage** pane that
     appears, specify values for the properties that you want to configure.

   - To configure instance properties related to backup and data
     replication, click **Data protection** . In the **Data protection**
     pane that appears, specify values for the properties that you want to
     configure.

   - To configure instance properties related to network interface and
     firewall settings, click **Networking** . In the **Networking** pane
     that appears, specify values for the properties that you want to
     configure.

   - To configure instance properties related to Ops agent and virtual
     displays, click **Observability** . In the **Observability** pane that
     appears, specify values for the properties that you want to configure.

   - To configure instance properties related to security and access, click
     **Security** . In the **Security** pane that appears, specify values
     for the properties that you want to configure.

   - To configure instance properties related to metadata, reservations,
     resource organization, provisioning type, and sole-tenancy, click
     **Advanced** . In the **Advanced** pane that appears, specify values
     for the properties that you want to configure.

3. To create and start your instance, click **Create**.

### gcloud

To create an instance with your own configuration, use the
[`gcloud compute instances create` command](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/create).

You can't use this command to create
[instances in bulk](https://docs.cloud.google.com/compute/docs/instances/multiple/create-in-bulk) or
[instances that run container images](https://docs.cloud.google.com/compute/docs/containers/deploying-containers).
Instead, do the following:

- To create instances in bulk, use the [`gcloud compute instances bulk create` command](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/bulk/create).
- To create instances to deploy containers, use the [`gcloud compute instances create-with-container` command](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/create-with-container).

### REST

To create an instance with your own configuration, make a `POST`
request to the
[`instances.insert` method](https://docs.cloud.google.com/compute/docs/reference/rest/v1/instances/insert).

You can't use this method to create
[instances in bulk](https://docs.cloud.google.com/compute/docs/instances/multiple/create-in-bulk).
Instead, make a `POST` request to the
[`instances.bulkInsert` method](https://docs.cloud.google.com/compute/docs/reference/rest/v1/instances/bulkInsert).

## Create and start instances with specific configurations

Each of the following documents provides instructions for how to create and
start an instance that uses one or more specific configuration options. Based
on your use case, you can create an instance that uses configuration options
from multiple documents by combining the instructions. To learn about the
various parameters that you can configure while creating your instance, review
[Configuration options available during instance creation](https://docs.cloud.google.com/compute/docs/instances/instance-creation-overview#new-instance-configuration-options).

Preconfigured for you
:   [Create a Google-configured, workload-optimized instance](https://docs.cloud.google.com/compute/docs/instances/create-workload-optimized-instance)

Customized machine configuration
:   [Create an instance with a custom hostname](https://docs.cloud.google.com/compute/docs/instances/custom-hostname-vm)
:   [Create an instance with a custom machine type](https://docs.cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type)
:   [Create an instance with attached GPUs](https://docs.cloud.google.com/compute/docs/gpus/create-vm-with-gpus)
:   [Create an instance with attached TPUs](https://docs.cloud.google.com/compute/docs/tpus/create-tpu-vm-instance)
:   [Specify a minimum CPU platform for an instance](https://docs.cloud.google.com/compute/docs/instances/specify-min-cpu-platform)

Customized OS configuration
:   [Create an instance from a public image](https://docs.cloud.google.com/compute/docs/instances/create-vm-from-public-image)
:   [Create an instance from a custom image](https://docs.cloud.google.com/compute/docs/instances/create-vm-from-custom-image)
:   [Create an instance from a shared image](https://docs.cloud.google.com/compute/docs/instances/create-vm-from-shared-image)
:   [Create an instance using a RHEL BYOS image](https://docs.cloud.google.com/compute/docs/instances/create-rhel-byos-vm)

Customized networking configuration
:   [Create an instance in a specific subnet](https://docs.cloud.google.com/compute/docs/instances/create-vm-specific-subnet)
:   [Create an instance that uses IPv6 addresses](https://docs.cloud.google.com/compute/docs/instances/create-ipv6-instance)
:   [Create instances that use the gVNIC network interface](https://docs.cloud.google.com/compute/docs/networking/using-gvnic#create_a_vm_with_gvnic_support)
:   [Configure an instance with higher bandwidth](https://docs.cloud.google.com/compute/docs/networking/configure-vm-with-high-bandwidth-configuration)

Customized observability configuration
:   [Create an instance that's configured for Ops Agent monitoring and logging](https://docs.cloud.google.com/compute/docs/instances/create-vm-ops-agent-monitoring-logging)
:   [Enable virtual displays on an instance](https://docs.cloud.google.com/compute/docs/instances/enable-instance-virtual-display)

Customized security configuration
:   [Create an instance that uses a user-managed service account](https://docs.cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances)
:   [Create VMs with managed workload identities enabled](https://docs.cloud.google.com/compute/docs/access/authenticate-workloads-over-mtls#create-workload-id-vms)
:   [Enable OS Login during VM creation](https://docs.cloud.google.com/compute/docs/oslogin/set-up-oslogin#enable_os_login_during_vm_creation)

Configured for disaster recovery
:   [Create an instance with a Backup and DR backup plan](https://docs.cloud.google.com/compute/docs/instances/create-instance-with-gcbdr-backup-plan)

From a backup
:   [Create an instance from a machine image](https://docs.cloud.google.com/compute/docs/machine-images/create-instance-from-machine-image)
:   [Create an instance from a disk snapshot](https://docs.cloud.google.com/compute/docs/disks/restore-snapshot)
:   [Restore an instance from a backup vault](https://docs.cloud.google.com/backup-disaster-recovery/docs/cloud-console/compute/compute-instance-restore)

From existing configurations
:   [Create an instance from an instance template](https://docs.cloud.google.com/compute/docs/instances/create-vm-from-instance-template)
:   [Create an instance similar to an existing instance](https://docs.cloud.google.com/compute/docs/instances/create-vm-from-similar-instance)

Configured for specific workloads
:   [Create an instance to deploy a container](https://docs.cloud.google.com/compute/docs/containers/deploying-containers#deploying_a_container_on_a_new_vm_instance)
:   [Create Windows Server instances](https://docs.cloud.google.com/compute/docs/instances/windows/creating-managing-windows-instances)
:   [Create SQL Server instances](https://docs.cloud.google.com/compute/docs/instances/sql-server/creating-sql-server-instances)
:   [Create an instance with a high performance computing (HPC) image](https://docs.cloud.google.com/compute/docs/instances/create-hpc-vm)

Customized provisioning type
:   [Create a Spot instance](https://docs.cloud.google.com/compute/docs/instances/create-use-spot)
:   [Create instances that consume reserved instances](https://docs.cloud.google.com/compute/docs/instances/reservations-consume)

Multiple instances at once
:   [Create a managed instance group (MIG)](https://docs.cloud.google.com/compute/docs/instance-groups/creating-groups-of-managed-instances#basic_scenarios_for_creating_a_mig)
:   [Create instances in bulk](https://docs.cloud.google.com/compute/docs/instances/multiple/create-in-bulk)

Sole-tenant nodes
:   [Create instances on sole-tenant nodes](https://docs.cloud.google.com/compute/docs/nodes/create-nodes)

Efficient instances
:   [Create an instance with an attached instance schedule](https://docs.cloud.google.com/compute/docs/instances/schedule-instance-start-stop#attaching_to_a_new_VM)

## Troubleshooting

To find methods for resolving common instance creation errors, see
[Troubleshooting instance creation](https://docs.cloud.google.com/compute/docs/troubleshooting/troubleshooting-vm-creation).


## What's next?

- Learn how to [check the status of an instance](https://docs.cloud.google.com/compute/docs/instances/instance-life-cycle) to see when it is ready to use.
- Learn how to [connect to your instance](https://docs.cloud.google.com/compute/docs/instances/connecting-to-instance).
- Learn how to [scale out your instance into a group of instances](https://docs.cloud.google.com/compute/docs/instance-groups/create-mig-from-vm).
- Learn how to [reserve capacity for your instances](https://docs.cloud.google.com/compute/docs/instances/choose-reservation-type).
- Learn how to save on instance costs through [committed use discounts](https://docs.cloud.google.com/compute/docs/instances/committed-use-discounts-overview) and [sustained use discounts](https://docs.cloud.google.com/compute/docs/sustained-use-discounts).