@@ -2186,6 +2186,60 @@ func TestAccComputeInstance_queueCount(t *testing.T) {
2186
2186
})
2187
2187
}
2188
2188
2189
+ func TestAccComputeInstance_spotVM (t * testing.T ) {
2190
+ t .Parallel ()
2191
+
2192
+ var instance compute.Instance
2193
+ var instanceName = fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
2194
+
2195
+ vcrTest (t , resource.TestCase {
2196
+ PreCheck : func () { testAccPreCheck (t ) },
2197
+ Providers : testAccProviders ,
2198
+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2199
+ Steps : []resource.TestStep {
2200
+ {
2201
+ Config : testAccComputeInstance_spotVM (instanceName ),
2202
+ Check : resource .ComposeTestCheckFunc (
2203
+ testAccCheckComputeInstanceExists (
2204
+ t , "google_compute_instance.foobar" , & instance ),
2205
+ ),
2206
+ },
2207
+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2208
+ },
2209
+ })
2210
+ }
2211
+
2212
+ func TestAccComputeInstance_spotVM_update (t * testing.T ) {
2213
+ t .Parallel ()
2214
+
2215
+ var instance compute.Instance
2216
+ var instanceName = fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
2217
+
2218
+ vcrTest (t , resource.TestCase {
2219
+ PreCheck : func () { testAccPreCheck (t ) },
2220
+ Providers : testAccProviders ,
2221
+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2222
+ Steps : []resource.TestStep {
2223
+ {
2224
+ Config : testAccComputeInstance_scheduling (instanceName ),
2225
+ Check : resource .ComposeTestCheckFunc (
2226
+ testAccCheckComputeInstanceExists (
2227
+ t , "google_compute_instance.foobar" , & instance ),
2228
+ ),
2229
+ },
2230
+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2231
+ {
2232
+ Config : testAccComputeInstance_spotVM (instanceName ),
2233
+ Check : resource .ComposeTestCheckFunc (
2234
+ testAccCheckComputeInstanceExists (
2235
+ t , "google_compute_instance.foobar" , & instance ),
2236
+ ),
2237
+ },
2238
+ computeInstanceImportStep ("us-central1-a" , instanceName , []string {}),
2239
+ },
2240
+ })
2241
+ }
2242
+
2189
2243
func TestComputeInstance_networkIPCustomizedDiff (t * testing.T ) {
2190
2244
t .Parallel ()
2191
2245
@@ -6084,3 +6138,35 @@ resource "google_compute_instance" "foobar" {
6084
6138
}
6085
6139
` , instance )
6086
6140
}
6141
+
6142
+ func testAccComputeInstance_spotVM (instance string ) string {
6143
+ return fmt .Sprintf (`
6144
+ data "google_compute_image" "my_image" {
6145
+ family = "ubuntu-2004-lts"
6146
+ project = "ubuntu-os-cloud"
6147
+ }
6148
+
6149
+ resource "google_compute_instance" "foobar" {
6150
+ name = "%s"
6151
+ machine_type = "e2-medium"
6152
+ zone = "us-central1-a"
6153
+
6154
+ boot_disk {
6155
+ initialize_params {
6156
+ image = data.google_compute_image.my_image.self_link
6157
+ }
6158
+ }
6159
+
6160
+ network_interface {
6161
+ network = "default"
6162
+ }
6163
+
6164
+ scheduling {
6165
+ provisioning_model = "SPOT"
6166
+ automatic_restart = false
6167
+ preemptible = true
6168
+ }
6169
+
6170
+ }
6171
+ ` , instance )
6172
+ }
0 commit comments