Fix Google instance template creation for preemptible VM

This commit is contained in:
Eric Robert 2016-01-21 14:37:10 +00:00
parent 2c48a7c4cb
commit 92d535267c
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)
}
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)