@@ -39,6 +39,34 @@ func TestAccComputeInstanceFromTemplate_basic(t *testing.T) {
39
39
})
40
40
}
41
41
42
+ func TestAccComputeInstanceFromTemplate_self_link_unique (t * testing.T ) {
43
+ t .Parallel ()
44
+
45
+ var instance compute.Instance
46
+ instanceName := fmt .Sprintf ("tf-test-%s" , RandString (t , 10 ))
47
+ templateName := fmt .Sprintf ("tf-test-%s" , RandString (t , 10 ))
48
+ resourceName := "google_compute_instance_from_template.foobar"
49
+
50
+ VcrTest (t , resource.TestCase {
51
+ PreCheck : func () { testAccPreCheck (t ) },
52
+ Providers : TestAccProviders ,
53
+ CheckDestroy : testAccCheckComputeInstanceFromTemplateDestroyProducer (t ),
54
+ Steps : []resource.TestStep {
55
+ {
56
+ Config : testAccComputeInstanceFromTemplate_self_link_unique (instanceName , templateName ),
57
+ Check : resource .ComposeTestCheckFunc (
58
+ testAccCheckComputeInstanceExists (t , resourceName , & instance ),
59
+
60
+ // Check that fields were set based on the template
61
+ resource .TestCheckResourceAttr (resourceName , "machine_type" , "n1-standard-1" ),
62
+ resource .TestCheckResourceAttr (resourceName , "attached_disk.#" , "1" ),
63
+ resource .TestCheckResourceAttr (resourceName , "scheduling.0.automatic_restart" , "false" ),
64
+ ),
65
+ },
66
+ },
67
+ })
68
+ }
69
+
42
70
func TestAccComputeInstanceFromRegionTemplate_basic (t * testing.T ) {
43
71
t .Parallel ()
44
72
@@ -413,6 +441,80 @@ resource "google_compute_instance_from_template" "foobar" {
413
441
` , template , template , instance )
414
442
}
415
443
444
+ func testAccComputeInstanceFromTemplate_self_link_unique (instance , template string ) string {
445
+ return fmt .Sprintf (`
446
+ data "google_compute_image" "my_image" {
447
+ family = "debian-11"
448
+ project = "debian-cloud"
449
+ }
450
+
451
+ resource "google_compute_disk" "foobar" {
452
+ name = "%s"
453
+ image = data.google_compute_image.my_image.self_link
454
+ size = 10
455
+ type = "pd-ssd"
456
+ zone = "us-central1-a"
457
+ }
458
+
459
+ resource "google_compute_instance_template" "foobar" {
460
+ name = "%s"
461
+ machine_type = "n1-standard-1" // can't be e2 because of local-ssd
462
+
463
+ disk {
464
+ source = google_compute_disk.foobar.name
465
+ auto_delete = false
466
+ boot = true
467
+ }
468
+
469
+ disk {
470
+ disk_type = "local-ssd"
471
+ type = "SCRATCH"
472
+ interface = "NVME"
473
+ disk_size_gb = 375
474
+ }
475
+
476
+ disk {
477
+ source_image = data.google_compute_image.my_image.self_link
478
+ auto_delete = true
479
+ disk_size_gb = 100
480
+ boot = false
481
+ disk_type = "pd-ssd"
482
+ type = "PERSISTENT"
483
+ }
484
+
485
+ network_interface {
486
+ network = "default"
487
+ }
488
+
489
+ metadata = {
490
+ foo = "bar"
491
+ }
492
+
493
+ scheduling {
494
+ automatic_restart = true
495
+ }
496
+
497
+ can_ip_forward = true
498
+ }
499
+
500
+ resource "google_compute_instance_from_template" "foobar" {
501
+ name = "%s"
502
+ zone = "us-central1-a"
503
+
504
+ source_instance_template = google_compute_instance_template.foobar.self_link_unique
505
+
506
+ // Overrides
507
+ can_ip_forward = false
508
+ labels = {
509
+ my_key = "my_value"
510
+ }
511
+ scheduling {
512
+ automatic_restart = false
513
+ }
514
+ }
515
+ ` , template , template , instance )
516
+ }
517
+
416
518
func testAccComputeInstanceFromTemplate_overrideBootDisk (templateDisk , overrideDisk , template , instance string ) string {
417
519
return fmt .Sprintf (`
418
520
data "google_compute_image" "my_image" {
0 commit comments