Skip to content

Commit 3a00247

Browse files
modular-magiciankotatut
authored andcommitted
compute: Add scheduling.termination_time field to compute_instance resources (#12791) (GoogleCloudPlatform#3554)
[upstream:fc3eeaab049d020371a96176262f2495ee9f7121] Signed-off-by: Modular Magician <[email protected]>
1 parent fefb4fb commit 3a00247

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

pkg/tfplan2cai/converters/services/compute/compute_instance_helpers.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func expandScheduling(v interface{}) (*compute.Scheduling, error) {
193193
scheduling.LocalSsdRecoveryTimeout = transformedLocalSsdRecoveryTimeout
194194
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "LocalSsdRecoveryTimeout")
195195
}
196+
if v, ok := original["termination_time"]; ok {
197+
scheduling.TerminationTime = v.(string)
198+
}
196199
return scheduling, nil
197200
}
198201

@@ -335,6 +338,7 @@ func flattenScheduling(resp *compute.Scheduling) []map[string]interface{} {
335338
"provisioning_model": resp.ProvisioningModel,
336339
"instance_termination_action": resp.InstanceTerminationAction,
337340
"availability_domain": resp.AvailabilityDomain,
341+
"termination_time": resp.TerminationTime,
338342
}
339343

340344
if resp.AutomaticRestart != nil {
@@ -776,7 +780,8 @@ func schedulingHasChangeRequiringReboot(d *schema.ResourceData) bool {
776780

777781
return hasNodeAffinitiesChanged(oScheduling, newScheduling) ||
778782
hasMaxRunDurationChanged(oScheduling, newScheduling) ||
779-
hasGracefulShutdownChangedWithReboot(d, oScheduling, newScheduling)
783+
hasGracefulShutdownChangedWithReboot(d, oScheduling, newScheduling) ||
784+
hasTerminationTimeChanged(oScheduling, newScheduling)
780785
}
781786

782787
// Terraform doesn't correctly calculate changes on schema.Set, so we do it manually
@@ -828,6 +833,24 @@ func schedulingHasChangeWithoutReboot(d *schema.ResourceData) bool {
828833
return false
829834
}
830835

836+
func hasTerminationTimeChanged(oScheduling, nScheduling map[string]interface{}) bool {
837+
oTerminationTime := oScheduling["termination_time"].(string)
838+
nTerminationTime := nScheduling["termination_time"].(string)
839+
840+
if len(oTerminationTime) == 0 && len(nTerminationTime) == 0 {
841+
return false
842+
}
843+
if len(oTerminationTime) == 0 || len(nTerminationTime) == 0 {
844+
return true
845+
}
846+
847+
if oTerminationTime != nTerminationTime {
848+
return true
849+
}
850+
851+
return false
852+
}
853+
831854
func hasGracefulShutdownChangedWithReboot(d *schema.ResourceData, oScheduling, nScheduling map[string]interface{}) bool {
832855
allow_stopping_for_update := d.Get("allow_stopping_for_update").(bool)
833856
if !allow_stopping_for_update {

tfplan2cai/converters/google/resources/services/compute/compute_instance_helpers.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func expandScheduling(v interface{}) (*compute.Scheduling, error) {
193193
scheduling.LocalSsdRecoveryTimeout = transformedLocalSsdRecoveryTimeout
194194
scheduling.ForceSendFields = append(scheduling.ForceSendFields, "LocalSsdRecoveryTimeout")
195195
}
196+
if v, ok := original["termination_time"]; ok {
197+
scheduling.TerminationTime = v.(string)
198+
}
196199
return scheduling, nil
197200
}
198201

@@ -335,6 +338,7 @@ func flattenScheduling(resp *compute.Scheduling) []map[string]interface{} {
335338
"provisioning_model": resp.ProvisioningModel,
336339
"instance_termination_action": resp.InstanceTerminationAction,
337340
"availability_domain": resp.AvailabilityDomain,
341+
"termination_time": resp.TerminationTime,
338342
}
339343

340344
if resp.AutomaticRestart != nil {
@@ -776,7 +780,8 @@ func schedulingHasChangeRequiringReboot(d *schema.ResourceData) bool {
776780

777781
return hasNodeAffinitiesChanged(oScheduling, newScheduling) ||
778782
hasMaxRunDurationChanged(oScheduling, newScheduling) ||
779-
hasGracefulShutdownChangedWithReboot(d, oScheduling, newScheduling)
783+
hasGracefulShutdownChangedWithReboot(d, oScheduling, newScheduling) ||
784+
hasTerminationTimeChanged(oScheduling, newScheduling)
780785
}
781786

782787
// Terraform doesn't correctly calculate changes on schema.Set, so we do it manually
@@ -828,6 +833,24 @@ func schedulingHasChangeWithoutReboot(d *schema.ResourceData) bool {
828833
return false
829834
}
830835

836+
func hasTerminationTimeChanged(oScheduling, nScheduling map[string]interface{}) bool {
837+
oTerminationTime := oScheduling["termination_time"].(string)
838+
nTerminationTime := nScheduling["termination_time"].(string)
839+
840+
if len(oTerminationTime) == 0 && len(nTerminationTime) == 0 {
841+
return false
842+
}
843+
if len(oTerminationTime) == 0 || len(nTerminationTime) == 0 {
844+
return true
845+
}
846+
847+
if oTerminationTime != nTerminationTime {
848+
return true
849+
}
850+
851+
return false
852+
}
853+
831854
func hasGracefulShutdownChangedWithReboot(d *schema.ResourceData, oScheduling, nScheduling map[string]interface{}) bool {
832855
allow_stopping_for_update := d.Get("allow_stopping_for_update").(bool)
833856
if !allow_stopping_for_update {

0 commit comments

Comments
 (0)