Terraform not supporting scheduling options in google cloud

I am trying to implement spot instance option in google cloud.

As part of that, I tried using the documentation in this link: google_compute_instance | Resources | hashicorp/google | Terraform Registry


provider "google" {
  credentials = file("service-account.json")
  project     = "project1"
  region      = "us-central1"
  zone        = "us-central1-c"
}

resource "google_compute_instance" "vm_instance" {
  name         = "terraform-instance"
  machine_type = "f1-micro"
  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = google_compute_network.vpc_network.self_link
  }
  scheduling {
    provisioning_model = SPOT
    preemptible        = true
    #auto_restart = false
  }
}

resource "google_compute_network" "vpc_network" {
  name                    = "terraform-network"
  auto_create_subnetworks = "true"
}

But getting below error.


╷
│ Error: Unsupported argument
│
│   22:     provisioning_model = SPOT
│
│ An argument named "provisioning_model" is not expected     
│ here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 24, in resource "google_compute_instance" "vm_instance":
│   24:     auto_restart = false
│
│ An argument named "auto_restart" is not expected here.     
╵
PS C:\Users\adminuser\Desktop\gke> terraform apply -auto-approve

╷
│ Error: Unsupported argument
│
│   on main.tf line 22, in resource "google_compute_instance" "vm_instance":
│   22:     provisioning_model = SPOT
│
│ An argument named "provisioning_model" is not expected     
│ here.

I am also facing similar issue while trying to create spot VMs in gcloud using terraform.

Works with google-beta provider

resource "google_compute_instance" "test-instance" {
  provider                  = google-beta

I had the same issue. Turns out I was using the wrong version of the google provider. Originally I had it configured as

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.5.0"
    }
  }
}

But it should have been…

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.50.0"
    }
  }
}

Note the change from 4.5.0 to 4.50.0 !

I know this is an older post, but I hope this helps someone else.