Create a spot instance using scheduling block

## Explore further


For detailed documentation that includes this code sample, see the following:

- [Create and use Spot VMs](https://docs.cloud.google.com/compute/docs/instances/create-use-spot)

## Code sample

### Terraform


To learn how to apply or remove a Terraform configuration, see
[Basic Terraform commands](https://docs.cloud.google.com/docs/terraform/basic-commands).


For more information, see the
[Terraform provider reference documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs).


    resource "google_compute_instance" "spot_vm_instance" {
      name         = "spot-instance-name"
      machine_type = "f1-micro"
      zone         = "us-central1-c"

      boot_disk {
        initialize_params {
          image = "debian-cloud/debian-13"
        }
      }

      scheduling {
        preemptible                 = true
        automatic_restart           = false
        provisioning_model          = "SPOT"
        instance_termination_action = "STOP"
      }

      network_interface {
        # A default network is created for all GCP projects
        network = "default"
        access_config {
        }
      }
    }

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=computeengine).