@@ -315,3 +315,110 @@ resource "google_compute_attached_disk" "test" {
315
315
}
316
316
` , diskPrefix , count , instanceName )
317
317
}
318
+
319
+ func TestAccComputeAttachedDisk_diskInterface (t * testing.T ) {
320
+ t .Parallel ()
321
+
322
+ diskName1 := fmt .Sprintf ("tf-test1-%d" , acctest .RandInt (t ))
323
+ diskName2 := fmt .Sprintf ("tf-test2-%d" , acctest .RandInt (t ))
324
+ attachedDiskName1 := fmt .Sprintf ("tf-test1-%d" , acctest .RandInt (t ))
325
+ attachedDiskName2 := fmt .Sprintf ("tf-test2-%d" , acctest .RandInt (t ))
326
+ instanceName1 := fmt .Sprintf ("tf-test1-%d" , acctest .RandInt (t ))
327
+ instanceName2 := fmt .Sprintf ("tf-test2-%d" , acctest .RandInt (t ))
328
+ importID1 := fmt .Sprintf ("%s/us-central1-a/%s/%s" , envvar .GetTestProjectFromEnv (), instanceName1 , diskName1 )
329
+ importID2 := fmt .Sprintf ("%s/us-central1-a/%s/%s" , envvar .GetTestProjectFromEnv (), instanceName2 , diskName2 )
330
+ acctest .VcrTest (t , resource.TestCase {
331
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
332
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
333
+ CheckDestroy : nil ,
334
+ Steps : []resource.TestStep {
335
+ {
336
+ Config : testAttachedDiskResource (diskName1 , instanceName1 ) + testAccComputeAttachedDisk_interface (attachedDiskName1 , "SCSI" ),
337
+ },
338
+ {
339
+ ResourceName : "google_compute_attached_disk." + attachedDiskName1 ,
340
+ ImportStateId : importID1 ,
341
+ ImportState : true ,
342
+ ImportStateVerify : false ,
343
+ },
344
+ {
345
+ Config : testAttachedDiskResource (diskName1 , instanceName1 ) + testAccComputeAttachedDisk_noInterface (attachedDiskName1 ),
346
+ },
347
+ {
348
+ ResourceName : "google_compute_attached_disk." + attachedDiskName1 ,
349
+ ImportStateId : importID1 ,
350
+ ImportState : true ,
351
+ ImportStateVerify : true ,
352
+ },
353
+ {
354
+ Config : testAttachedDiskResource (diskName1 , instanceName1 ) + testAccComputeAttachedDisk_interface (attachedDiskName1 , "SCSI" ),
355
+ },
356
+ {
357
+ ResourceName : "google_compute_attached_disk." + attachedDiskName1 ,
358
+ ImportStateId : importID1 ,
359
+ ImportState : true ,
360
+ ImportStateVerify : false ,
361
+ },
362
+ // API server will use NVME even SCSI is specified
363
+ {
364
+ Config : testAttachedDiskResourceWithMachineType (diskName2 , instanceName2 , "h3-standard-88" ) + testAccComputeAttachedDisk_interface (attachedDiskName2 , "SCSI" ),
365
+ },
366
+ {
367
+ ResourceName : "google_compute_attached_disk." + attachedDiskName2 ,
368
+ ImportStateId : importID2 ,
369
+ ImportState : true ,
370
+ ImportStateVerify : false ,
371
+ },
372
+ },
373
+ })
374
+
375
+ }
376
+
377
+ func testAccComputeAttachedDisk_interface (resourceName , diskInterface string ) string {
378
+ return fmt .Sprintf (`
379
+ resource "google_compute_attached_disk" "%s" {
380
+ disk = google_compute_disk.test1.self_link
381
+ instance = google_compute_instance.test.self_link
382
+ interface = "%s"
383
+ }
384
+ ` , resourceName , diskInterface )
385
+ }
386
+
387
+ func testAccComputeAttachedDisk_noInterface (resourceName string ) string {
388
+ return fmt .Sprintf (`
389
+ resource "google_compute_attached_disk" "%s" {
390
+ disk = google_compute_disk.test1.self_link
391
+ instance = google_compute_instance.test.self_link
392
+ }
393
+ ` , resourceName )
394
+ }
395
+
396
+ func testAttachedDiskResourceWithMachineType (diskName , instanceName , machineType string ) string {
397
+ return fmt .Sprintf (`
398
+ resource "google_compute_disk" "test1" {
399
+ name = "%s"
400
+ zone = "us-central1-a"
401
+ type = "hyperdisk-balanced"
402
+ }
403
+
404
+ resource "google_compute_instance" "test" {
405
+ name = "%s"
406
+ machine_type = "%s"
407
+ zone = "us-central1-a"
408
+
409
+ lifecycle {
410
+ ignore_changes = [attached_disk]
411
+ }
412
+
413
+ boot_disk {
414
+ initialize_params {
415
+ image = "debian-cloud/debian-11"
416
+ }
417
+ }
418
+
419
+ network_interface {
420
+ network = "default"
421
+ }
422
+ }
423
+ ` , diskName , instanceName , machineType )
424
+ }
0 commit comments