@@ -5,6 +5,7 @@ package compute_test
5
5
import (
6
6
"fmt"
7
7
"testing"
8
+ "time"
8
9
9
10
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10
11
"github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -76,6 +77,35 @@ func TestAccComputeInstanceFromMachineImage_maxRunDuration(t *testing.T) {
76
77
})
77
78
}
78
79
80
+ func TestAccComputeInstanceFromMachineImage_terminationTime (t * testing.T ) {
81
+ t .Parallel ()
82
+
83
+ var instance compute.Instance
84
+ instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
85
+ generatedInstanceName := fmt .Sprintf ("tf-test-generated-%s" , acctest .RandString (t , 10 ))
86
+ resourceName := "google_compute_instance_from_machine_image.foobar"
87
+ now := time .Now ().UTC ()
88
+ terminationTime := time .Date (now .Year (), now .Month (), now .Day (), 23 , 59 , 59 , 9999 , now .Location ()).Format (time .RFC3339 )
89
+
90
+ acctest .VcrTest (t , resource.TestCase {
91
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
92
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderBetaFactories (t ),
93
+ CheckDestroy : testAccCheckComputeInstanceFromMachineImageDestroyProducer (t ),
94
+ Steps : []resource.TestStep {
95
+ {
96
+ Config : testAccComputeInstanceFromMachineImage_terminationTime (instanceName , generatedInstanceName , terminationTime ),
97
+ Check : resource .ComposeTestCheckFunc (
98
+ testAccCheckComputeInstanceExists (t , resourceName , & instance ),
99
+
100
+ // Check that fields were set based on the template
101
+ resource .TestCheckResourceAttr (resourceName , "scheduling.0.automatic_restart" , "false" ),
102
+ resource .TestCheckResourceAttr (resourceName , "scheduling.0.termination_time" , terminationTime ),
103
+ ),
104
+ },
105
+ },
106
+ })
107
+ }
108
+
79
109
func TestAccComputeInstanceFromMachineImage_localSsdRecoveryTimeout (t * testing.T ) {
80
110
t .Parallel ()
81
111
@@ -699,6 +729,65 @@ resource "google_compute_instance_from_machine_image" "foobar" {
699
729
` , instance , instance , newInstance )
700
730
}
701
731
732
+ func testAccComputeInstanceFromMachineImage_terminationTime (instance , newInstance , terminationTime string ) string {
733
+ return fmt .Sprintf (`
734
+ resource "google_compute_instance" "vm" {
735
+ provider = google-beta
736
+
737
+ boot_disk {
738
+ initialize_params {
739
+ image = "debian-cloud/debian-12"
740
+ }
741
+ }
742
+
743
+ name = "%s"
744
+ machine_type = "n1-standard-1"
745
+
746
+ network_interface {
747
+ network = "default"
748
+ }
749
+
750
+ metadata = {
751
+ foo = "bar"
752
+ }
753
+
754
+ scheduling {
755
+ automatic_restart = false
756
+ instance_termination_action = "STOP"
757
+ termination_time = "%s"
758
+ }
759
+
760
+ }
761
+
762
+ resource "google_compute_machine_image" "foobar" {
763
+ provider = google-beta
764
+ name = "%s"
765
+ source_instance = google_compute_instance.vm.self_link
766
+ }
767
+
768
+ resource "google_compute_instance_from_machine_image" "foobar" {
769
+ provider = google-beta
770
+ name = "%s"
771
+ zone = "us-central1-a"
772
+
773
+ source_machine_image = google_compute_machine_image.foobar.self_link
774
+
775
+ labels = {
776
+ my_key = "my_value"
777
+ }
778
+ scheduling {
779
+ automatic_restart = false
780
+ provisioning_model = "STANDARD"
781
+ instance_termination_action = "STOP"
782
+ termination_time = "%s"
783
+ on_instance_stop_action {
784
+ discard_local_ssd = true
785
+ }
786
+ }
787
+ }
788
+ ` , instance , terminationTime , instance , newInstance , terminationTime )
789
+ }
790
+
702
791
func testAccComputeInstanceFromMachineImage_localSsdRecoveryTimeout (instance , newInstance string ) string {
703
792
return fmt .Sprintf (`
704
793
resource "google_compute_instance" "vm" {
0 commit comments