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