From 92d535267c56d17cfb024aef43b0c3a8ae2645ee Mon Sep 17 00:00:00 2001 From: Eric Robert Date: Thu, 21 Jan 2016 14:37:10 +0000 Subject: [PATCH] Fix Google instance template creation for preemptible VM --- .../google/resource_compute_instance_template.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/providers/google/resource_compute_instance_template.go b/builtin/providers/google/resource_compute_instance_template.go index b0e26d0f9..4128fbccc 100644 --- a/builtin/providers/google/resource_compute_instance_template.go +++ b/builtin/providers/google/resource_compute_instance_template.go @@ -442,6 +442,9 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac instanceProperties.Scheduling.OnHostMaintenance = v.(string) } + forceSendFieldsScheduling := make([]string, 0, 3) + var hasSendMaintenance bool + hasSendMaintenance = false if v, ok := d.GetOk("scheduling"); ok { _schedulings := v.([]interface{}) if len(_schedulings) > 1 { @@ -451,16 +454,25 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac if vp, okp := _scheduling["automatic_restart"]; okp { instanceProperties.Scheduling.AutomaticRestart = vp.(bool) + forceSendFieldsScheduling = append(forceSendFieldsScheduling, "AutomaticRestart") } if vp, okp := _scheduling["on_host_maintenance"]; okp { instanceProperties.Scheduling.OnHostMaintenance = vp.(string) + forceSendFieldsScheduling = append(forceSendFieldsScheduling, "OnHostMaintenance") + hasSendMaintenance = true } if vp, okp := _scheduling["preemptible"]; okp { instanceProperties.Scheduling.Preemptible = vp.(bool) + forceSendFieldsScheduling = append(forceSendFieldsScheduling, "Preemptible") + if vp.(bool) && !hasSendMaintenance { + instanceProperties.Scheduling.OnHostMaintenance = "TERMINATE" + forceSendFieldsScheduling = append(forceSendFieldsScheduling, "OnHostMaintenance") + } } } + instanceProperties.Scheduling.ForceSendFields = forceSendFieldsScheduling serviceAccountsCount := d.Get("service_account.#").(int) serviceAccounts := make([]*compute.ServiceAccount, 0, serviceAccountsCount)