From 547245badafc4b86323cabf2ce0bbef440481e18 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Mon, 16 Jul 2018 13:54:47 -0700 Subject: [PATCH] allow setting instance scheduling booleans to false --- google/resource_compute_instance.go | 34 +++++++----------------- google/resource_compute_instance_test.go | 1 + 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/google/resource_compute_instance.go b/google/resource_compute_instance.go index 3ed086b060b..85d04108d56 100644 --- a/google/resource_compute_instance.go +++ b/google/resource_compute_instance.go @@ -667,20 +667,12 @@ func expandComputeInstance(project string, zone *compute.Zone, d *schema.Resourc } prefix := "scheduling.0" - scheduling := &computeBeta.Scheduling{} - - if val, ok := d.GetOk(prefix + ".automatic_restart"); ok { - scheduling.AutomaticRestart = googleapi.Bool(val.(bool)) - } - - if val, ok := d.GetOk(prefix + ".preemptible"); ok { - scheduling.Preemptible = val.(bool) - } - - if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok { - scheduling.OnHostMaintenance = val.(string) + 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"}, } - scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"} metadata, err := resourceInstanceMetadata(d) if err != nil { @@ -1069,18 +1061,12 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err if d.HasChange("scheduling") { prefix := "scheduling.0" - scheduling := &compute.Scheduling{} - - if val, ok := d.GetOk(prefix + ".automatic_restart"); ok { - scheduling.AutomaticRestart = googleapi.Bool(val.(bool)) - } - if val, ok := d.GetOk(prefix + ".preemptible"); ok { - scheduling.Preemptible = val.(bool) - } - if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok { - scheduling.OnHostMaintenance = val.(string) + scheduling := &compute.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"}, } - scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"} op, err := config.clientCompute.Instances.SetScheduling(project, zone, d.Id(), scheduling).Do() diff --git a/google/resource_compute_instance_test.go b/google/resource_compute_instance_test.go index d24708d5c06..dbc3af116ff 100644 --- a/google/resource_compute_instance_test.go +++ b/google/resource_compute_instance_test.go @@ -2339,6 +2339,7 @@ resource "google_compute_instance" "foobar" { } scheduling { + automatic_restart = false } } `, instance)