Merge pull request #4834 from erobert-c/gce_instance_template_preemptible

Fix Google instance template creation for preemptible VM
This commit is contained in:
Lars Wander 2016-03-09 10:34:20 -05:00
commit b0d53a99c2
1 changed files with 12 additions and 0 deletions

View File

@ -442,6 +442,9 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
instanceProperties.Scheduling.OnHostMaintenance = v.(string) instanceProperties.Scheduling.OnHostMaintenance = v.(string)
} }
forceSendFieldsScheduling := make([]string, 0, 3)
var hasSendMaintenance bool
hasSendMaintenance = false
if v, ok := d.GetOk("scheduling"); ok { if v, ok := d.GetOk("scheduling"); ok {
_schedulings := v.([]interface{}) _schedulings := v.([]interface{})
if len(_schedulings) > 1 { if len(_schedulings) > 1 {
@ -451,16 +454,25 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
if vp, okp := _scheduling["automatic_restart"]; okp { if vp, okp := _scheduling["automatic_restart"]; okp {
instanceProperties.Scheduling.AutomaticRestart = vp.(bool) instanceProperties.Scheduling.AutomaticRestart = vp.(bool)
forceSendFieldsScheduling = append(forceSendFieldsScheduling, "AutomaticRestart")
} }
if vp, okp := _scheduling["on_host_maintenance"]; okp { if vp, okp := _scheduling["on_host_maintenance"]; okp {
instanceProperties.Scheduling.OnHostMaintenance = vp.(string) instanceProperties.Scheduling.OnHostMaintenance = vp.(string)
forceSendFieldsScheduling = append(forceSendFieldsScheduling, "OnHostMaintenance")
hasSendMaintenance = true
} }
if vp, okp := _scheduling["preemptible"]; okp { if vp, okp := _scheduling["preemptible"]; okp {
instanceProperties.Scheduling.Preemptible = vp.(bool) 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) serviceAccountsCount := d.Get("service_account.#").(int)
serviceAccounts := make([]*compute.ServiceAccount, 0, serviceAccountsCount) serviceAccounts := make([]*compute.ServiceAccount, 0, serviceAccountsCount)