From 1663bb84281800b4fefa9b1ffc1bcd38e470ad2c Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 12 Dec 2018 09:32:16 -0800 Subject: [PATCH] send scheduling block with automaticrestart if there is none in cfg (#210) --- google-beta/resource_compute_instance.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/google-beta/resource_compute_instance.go b/google-beta/resource_compute_instance.go index 39c6a00550..7d4ac12864 100644 --- a/google-beta/resource_compute_instance.go +++ b/google-beta/resource_compute_instance.go @@ -625,12 +625,22 @@ func expandComputeInstance(project string, zone *compute.Zone, d *schema.Resourc disks = append(disks, disk) } - prefix := "scheduling.0" - scheduling := &computeBeta.Scheduling{ - AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)), - Preemptible: d.Get(prefix + ".preemptible").(bool), - OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string), - ForceSendFields: []string{"AutomaticRestart", "Preemptible"}, + sch := d.Get("scheduling").([]interface{}) + var scheduling *computeBeta.Scheduling + if len(sch) == 0 { + // TF doesn't do anything about defaults inside of nested objects, so if + // scheduling hasn't been set, then send it with its default values. + scheduling = &computeBeta.Scheduling{ + AutomaticRestart: googleapi.Bool(true), + } + } else { + prefix := "scheduling.0" + scheduling = &computeBeta.Scheduling{ + AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)), + Preemptible: d.Get(prefix + ".preemptible").(bool), + OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string), + ForceSendFields: []string{"AutomaticRestart", "Preemptible"}, + } } metadata, err := resourceInstanceMetadata(d)