Skip to content

Commit 547245b

Browse files
committed
allow setting instance scheduling booleans to false
1 parent b00b1d7 commit 547245b

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

google/resource_compute_instance.go

+10-24
Original file line numberDiff line numberDiff line change
@@ -667,20 +667,12 @@ func expandComputeInstance(project string, zone *compute.Zone, d *schema.Resourc
667667
}
668668

669669
prefix := "scheduling.0"
670-
scheduling := &computeBeta.Scheduling{}
671-
672-
if val, ok := d.GetOk(prefix + ".automatic_restart"); ok {
673-
scheduling.AutomaticRestart = googleapi.Bool(val.(bool))
674-
}
675-
676-
if val, ok := d.GetOk(prefix + ".preemptible"); ok {
677-
scheduling.Preemptible = val.(bool)
678-
}
679-
680-
if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok {
681-
scheduling.OnHostMaintenance = val.(string)
670+
scheduling := &computeBeta.Scheduling{
671+
AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)),
672+
Preemptible: d.Get(prefix + ".preemptible").(bool),
673+
OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string),
674+
ForceSendFields: []string{"AutomaticRestart", "Preemptible"},
682675
}
683-
scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"}
684676

685677
metadata, err := resourceInstanceMetadata(d)
686678
if err != nil {
@@ -1069,18 +1061,12 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
10691061

10701062
if d.HasChange("scheduling") {
10711063
prefix := "scheduling.0"
1072-
scheduling := &compute.Scheduling{}
1073-
1074-
if val, ok := d.GetOk(prefix + ".automatic_restart"); ok {
1075-
scheduling.AutomaticRestart = googleapi.Bool(val.(bool))
1076-
}
1077-
if val, ok := d.GetOk(prefix + ".preemptible"); ok {
1078-
scheduling.Preemptible = val.(bool)
1079-
}
1080-
if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok {
1081-
scheduling.OnHostMaintenance = val.(string)
1064+
scheduling := &compute.Scheduling{
1065+
AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)),
1066+
Preemptible: d.Get(prefix + ".preemptible").(bool),
1067+
OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string),
1068+
ForceSendFields: []string{"AutomaticRestart", "Preemptible"},
10821069
}
1083-
scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"}
10841070

10851071
op, err := config.clientCompute.Instances.SetScheduling(project,
10861072
zone, d.Id(), scheduling).Do()

google/resource_compute_instance_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ resource "google_compute_instance" "foobar" {
23392339
}
23402340
23412341
scheduling {
2342+
automatic_restart = false
23422343
}
23432344
}
23442345
`, instance)

0 commit comments

Comments
 (0)