@@ -70,6 +70,66 @@ func TestAccComputeInstanceFromTemplate_self_link_unique(t *testing.T) {
70
70
})
71
71
}
72
72
73
+ func TestAccComputeInstanceFromTemplate_localSsdRecoveryTimeout (t * testing.T ) {
74
+ t .Parallel ()
75
+
76
+ var instance compute.Instance
77
+ instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
78
+ templateName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
79
+ resourceName := "google_compute_instance_from_template.foobar"
80
+
81
+ var expectedLocalSsdRecoveryTimeout = compute.Duration {}
82
+ expectedLocalSsdRecoveryTimeout .Nanos = 0
83
+ expectedLocalSsdRecoveryTimeout .Seconds = 3600
84
+
85
+ acctest .VcrTest (t , resource.TestCase {
86
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
87
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
88
+ CheckDestroy : testAccCheckComputeInstanceFromTemplateDestroyProducer (t ),
89
+ Steps : []resource.TestStep {
90
+ {
91
+ Config : testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout (instanceName , templateName ),
92
+ Check : resource .ComposeTestCheckFunc (
93
+ testAccCheckComputeInstanceExists (t , resourceName , & instance ),
94
+
95
+ // Check that fields were set based on the template
96
+ testAccCheckComputeInstanceLocalSsdRecoveryTimeout (& instance , expectedLocalSsdRecoveryTimeout ),
97
+ ),
98
+ },
99
+ },
100
+ })
101
+ }
102
+
103
+ func TestAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout (t * testing.T ) {
104
+ t .Parallel ()
105
+
106
+ var instance compute.Instance
107
+ instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
108
+ templateName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
109
+ resourceName := "google_compute_instance_from_template.foobar"
110
+
111
+ var expectedLocalSsdRecoveryTimeout = compute.Duration {}
112
+ expectedLocalSsdRecoveryTimeout .Nanos = 0
113
+ expectedLocalSsdRecoveryTimeout .Seconds = 7200
114
+
115
+ acctest .VcrTest (t , resource.TestCase {
116
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
117
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
118
+ CheckDestroy : testAccCheckComputeInstanceFromTemplateDestroyProducer (t ),
119
+ Steps : []resource.TestStep {
120
+ {
121
+ Config : testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout (instanceName , templateName ),
122
+ Check : resource .ComposeTestCheckFunc (
123
+ testAccCheckComputeInstanceExists (t , resourceName , & instance ),
124
+
125
+ // Check that fields were set based on the template
126
+ testAccCheckComputeInstanceLocalSsdRecoveryTimeout (& instance , expectedLocalSsdRecoveryTimeout ),
127
+ ),
128
+ },
129
+ },
130
+ })
131
+ }
132
+
73
133
func TestAccComputeInstanceFromTemplate_overrideBootDisk (t * testing.T ) {
74
134
t .Parallel ()
75
135
@@ -341,6 +401,166 @@ resource "google_compute_instance_from_template" "foobar" {
341
401
` , template , template , instance )
342
402
}
343
403
404
+ func testAccComputeInstanceFromTemplate_localSsdRecoveryTimeout (instance , template string ) string {
405
+ return fmt .Sprintf (`
406
+ data "google_compute_image" "my_image" {
407
+ family = "debian-11"
408
+ project = "debian-cloud"
409
+ }
410
+
411
+ resource "google_compute_disk" "foobar" {
412
+ name = "%s"
413
+ image = data.google_compute_image.my_image.self_link
414
+ size = 10
415
+ type = "pd-ssd"
416
+ zone = "us-central1-a"
417
+ }
418
+
419
+ resource "google_compute_instance_template" "foobar" {
420
+ name = "%s"
421
+ machine_type = "n1-standard-1" // can't be e2 because of local-ssd
422
+
423
+ disk {
424
+ source = google_compute_disk.foobar.name
425
+ auto_delete = false
426
+ boot = true
427
+ }
428
+
429
+ disk {
430
+ disk_type = "local-ssd"
431
+ type = "SCRATCH"
432
+ interface = "NVME"
433
+ disk_size_gb = 375
434
+ }
435
+
436
+ disk {
437
+ source_image = data.google_compute_image.my_image.self_link
438
+ auto_delete = true
439
+ disk_size_gb = 100
440
+ boot = false
441
+ disk_type = "pd-ssd"
442
+ type = "PERSISTENT"
443
+ }
444
+
445
+ network_interface {
446
+ network = "default"
447
+ }
448
+
449
+ metadata = {
450
+ foo = "bar"
451
+ }
452
+
453
+ scheduling {
454
+ automatic_restart = true
455
+ local_ssd_recovery_timeout {
456
+ nanos = 0
457
+ seconds = 3600
458
+ }
459
+ }
460
+
461
+ can_ip_forward = true
462
+ }
463
+
464
+ resource "google_compute_instance_from_template" "foobar" {
465
+ name = "%s"
466
+ zone = "us-central1-a"
467
+
468
+ source_instance_template = google_compute_instance_template.foobar.self_link
469
+
470
+ // Overrides
471
+ can_ip_forward = false
472
+ labels = {
473
+ my_key = "my_value"
474
+ }
475
+ scheduling {
476
+ automatic_restart = false
477
+ }
478
+ }
479
+ ` , template , template , instance )
480
+ }
481
+
482
+ func testAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout (instance , template string ) string {
483
+ return fmt .Sprintf (`
484
+ data "google_compute_image" "my_image" {
485
+ family = "debian-11"
486
+ project = "debian-cloud"
487
+ }
488
+
489
+ resource "google_compute_disk" "foobar" {
490
+ name = "%s"
491
+ image = data.google_compute_image.my_image.self_link
492
+ size = 10
493
+ type = "pd-ssd"
494
+ zone = "us-central1-a"
495
+ }
496
+
497
+ resource "google_compute_instance_template" "foobar" {
498
+ name = "%s"
499
+ machine_type = "n1-standard-1" // can't be e2 because of local-ssd
500
+
501
+ disk {
502
+ source = google_compute_disk.foobar.name
503
+ auto_delete = false
504
+ boot = true
505
+ }
506
+
507
+ disk {
508
+ disk_type = "local-ssd"
509
+ type = "SCRATCH"
510
+ interface = "NVME"
511
+ disk_size_gb = 375
512
+ }
513
+
514
+ disk {
515
+ source_image = data.google_compute_image.my_image.self_link
516
+ auto_delete = true
517
+ disk_size_gb = 100
518
+ boot = false
519
+ disk_type = "pd-ssd"
520
+ type = "PERSISTENT"
521
+ }
522
+
523
+ network_interface {
524
+ network = "default"
525
+ }
526
+
527
+ metadata = {
528
+ foo = "bar"
529
+ }
530
+
531
+ scheduling {
532
+ automatic_restart = true
533
+ local_ssd_recovery_timeout {
534
+ nanos = 0
535
+ seconds = 3600
536
+ }
537
+ }
538
+
539
+ can_ip_forward = true
540
+ }
541
+
542
+ resource "google_compute_instance_from_template" "foobar" {
543
+ name = "%s"
544
+ zone = "us-central1-a"
545
+
546
+ source_instance_template = google_compute_instance_template.foobar.self_link
547
+
548
+ // Overrides
549
+ can_ip_forward = false
550
+ labels = {
551
+ my_key = "my_value"
552
+ }
553
+ scheduling {
554
+ automatic_restart = false
555
+ local_ssd_recovery_timeout {
556
+ nanos = 0
557
+ seconds = 7200
558
+ }
559
+ }
560
+ }
561
+ ` , template , template , instance )
562
+ }
563
+
344
564
func testAccComputeInstanceFromTemplate_self_link_unique (instance , template string ) string {
345
565
return fmt .Sprintf (`
346
566
data "google_compute_image" "my_image" {
0 commit comments