@@ -1319,6 +1319,37 @@ func TestAccComputeInstanceTemplate_maxRunDuration_onInstanceStopAction(t *testi
1319
1319
})
1320
1320
}
1321
1321
1322
+ func TestAccComputeInstanceTemplate_instanceTerminationAction_terminationTime (t * testing.T ) {
1323
+ t .Parallel ()
1324
+
1325
+ var instanceTemplate compute.InstanceTemplate
1326
+ now := time .Now ().UTC ()
1327
+ terminationTime := time .Date (now .Year (), now .Month (), now .Day (), 23 , 59 , 59 , 9999 , now .Location ()).Format (time .RFC3339 )
1328
+ var instanceTerminationAction = "STOP"
1329
+
1330
+ acctest .VcrTest (t , resource.TestCase {
1331
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1332
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1333
+ CheckDestroy : testAccCheckComputeInstanceTemplateDestroyProducer (t ),
1334
+ Steps : []resource.TestStep {
1335
+ {
1336
+ Config : testAccComputeInstanceTemplate_onInstanceStopAction_terminationTime (acctest .RandString (t , 10 ), terminationTime ),
1337
+ Check : resource .ComposeTestCheckFunc (
1338
+ testAccCheckComputeInstanceTemplateExists (
1339
+ t , "google_compute_instance_template.foobar" , & instanceTemplate ),
1340
+ testAccCheckComputeInstanceTemplateInstanceTerminationAction (& instanceTemplate , instanceTerminationAction ),
1341
+ testAccCheckComputeInstanceTemplateInstanceTerminationTime (& instanceTemplate , terminationTime ),
1342
+ ),
1343
+ },
1344
+ {
1345
+ ResourceName : "google_compute_instance_template.foobar" ,
1346
+ ImportState : true ,
1347
+ ImportStateVerify : true ,
1348
+ },
1349
+ },
1350
+ })
1351
+ }
1352
+
1322
1353
func TestAccComputeInstanceTemplate_spot_maxRunDuration (t * testing.T ) {
1323
1354
t .Parallel ()
1324
1355
@@ -1857,6 +1888,15 @@ func testAccCheckComputeInstanceTemplateInstanceTerminationAction(instanceTempla
1857
1888
}
1858
1889
}
1859
1890
1891
+ func testAccCheckComputeInstanceTemplateInstanceTerminationTime (instanceTemplate * compute.InstanceTemplate , termination_time string ) resource.TestCheckFunc {
1892
+ return func (s * terraform.State ) error {
1893
+ if instanceTemplate .Properties .Scheduling .TerminationTime != termination_time {
1894
+ return fmt .Errorf ("Expected instance_termination_time %v, got %v" , termination_time , instanceTemplate .Properties .Scheduling .TerminationTime )
1895
+ }
1896
+ return nil
1897
+ }
1898
+ }
1899
+
1860
1900
func testAccCheckComputeInstanceTemplateMaxRunDuration (instanceTemplate * compute.InstanceTemplate , instance_max_run_duration_want compute.Duration ) resource.TestCheckFunc {
1861
1901
return func (s * terraform.State ) error {
1862
1902
if ! reflect .DeepEqual (* instanceTemplate .Properties .Scheduling .MaxRunDuration , instance_max_run_duration_want ) {
@@ -4071,6 +4111,46 @@ resource "google_compute_instance_template" "foobar" {
4071
4111
` , suffix )
4072
4112
}
4073
4113
4114
+ func testAccComputeInstanceTemplate_onInstanceStopAction_terminationTime (suffix string , terminationTime string ) string {
4115
+ return fmt .Sprintf (`
4116
+ data "google_compute_image" "my_image" {
4117
+ family = "debian-11"
4118
+ project = "debian-cloud"
4119
+ }
4120
+
4121
+ resource "google_compute_instance_template" "foobar" {
4122
+ name = "tf-test-instance-template-%s"
4123
+ machine_type = "e2-medium"
4124
+ can_ip_forward = false
4125
+ tags = ["foo", "bar"]
4126
+
4127
+ disk {
4128
+ source_image = data.google_compute_image.my_image.self_link
4129
+ auto_delete = true
4130
+ boot = true
4131
+ }
4132
+
4133
+ network_interface {
4134
+ network = "default"
4135
+ }
4136
+
4137
+ scheduling {
4138
+ automatic_restart = false
4139
+ instance_termination_action = "STOP"
4140
+ termination_time = "%s"
4141
+ }
4142
+
4143
+ metadata = {
4144
+ foo = "bar"
4145
+ }
4146
+
4147
+ service_account {
4148
+ scopes = ["userinfo-email", "compute-ro", "storage-ro"]
4149
+ }
4150
+ }
4151
+ ` , suffix , terminationTime )
4152
+ }
4153
+
4074
4154
func testAccComputeInstanceTemplate_localSsdRecoveryTimeout (suffix string ) string {
4075
4155
return fmt .Sprintf (`
4076
4156
data "google_compute_image" "my_image" {
0 commit comments