@@ -2210,6 +2210,60 @@ func TestAccComputeInstance_queueCount(t *testing.T) {
22102210 })
22112211}
22122212
2213+ func TestAccComputeInstance_spotVM (t * testing.T ) {
2214+ t .Parallel ()
2215+
2216+ var instance compute.Instance
2217+ var instanceName = fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
2218+
2219+ vcrTest (t , resource.TestCase {
2220+ PreCheck : func () { testAccPreCheck (t ) },
2221+ Providers : testAccProviders ,
2222+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2223+ Steps : []resource.TestStep {
2224+ {
2225+ Config : testAccComputeInstance_spotVM (instanceName ),
2226+ Check : resource .ComposeTestCheckFunc (
2227+ testAccCheckComputeInstanceExists (
2228+ t , "google_compute_instance.foobar" , & instance ),
2229+ ),
2230+ },
2231+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2232+ },
2233+ })
2234+ }
2235+
2236+ func TestAccComputeInstance_spotVM_update (t * testing.T ) {
2237+ t .Parallel ()
2238+
2239+ var instance compute.Instance
2240+ var instanceName = fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
2241+
2242+ vcrTest (t , resource.TestCase {
2243+ PreCheck : func () { testAccPreCheck (t ) },
2244+ Providers : testAccProviders ,
2245+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2246+ Steps : []resource.TestStep {
2247+ {
2248+ Config : testAccComputeInstance_scheduling (instanceName ),
2249+ Check : resource .ComposeTestCheckFunc (
2250+ testAccCheckComputeInstanceExists (
2251+ t , "google_compute_instance.foobar" , & instance ),
2252+ ),
2253+ },
2254+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2255+ {
2256+ Config : testAccComputeInstance_spotVM (instanceName ),
2257+ Check : resource .ComposeTestCheckFunc (
2258+ testAccCheckComputeInstanceExists (
2259+ t , "google_compute_instance.foobar" , & instance ),
2260+ ),
2261+ },
2262+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2263+ },
2264+ })
2265+ }
2266+
22132267func TestComputeInstance_networkIPCustomizedDiff (t * testing.T ) {
22142268 t .Parallel ()
22152269
@@ -6170,3 +6224,35 @@ resource "google_compute_instance" "foobar" {
61706224}
61716225` , instance )
61726226}
6227+
6228+ func testAccComputeInstance_spotVM (instance string ) string {
6229+ return fmt .Sprintf (`
6230+ data "google_compute_image" "my_image" {
6231+ family = "ubuntu-2004-lts"
6232+ project = "ubuntu-os-cloud"
6233+ }
6234+
6235+ resource "google_compute_instance" "foobar" {
6236+ name = "%s"
6237+ machine_type = "e2-medium"
6238+ zone = "us-central1-a"
6239+
6240+ boot_disk {
6241+ initialize_params {
6242+ image = data.google_compute_image.my_image.self_link
6243+ }
6244+ }
6245+
6246+ network_interface {
6247+ network = "default"
6248+ }
6249+
6250+ scheduling {
6251+ provisioning_model = "SPOT"
6252+ automatic_restart = false
6253+ preemptible = true
6254+ }
6255+
6256+ }
6257+ ` , instance )
6258+ }
0 commit comments