Skip to content

Commit

Permalink
Merge pull request #1779 from danawillow/is-1775
Browse files Browse the repository at this point in the history
allow setting instance scheduling booleans to false
  • Loading branch information
paddycarver authored Jul 17, 2018
2 parents 4e0a4ef + 547245b commit 1fea758
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
34 changes: 10 additions & 24 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,7 @@ resource "google_compute_instance" "foobar" {
}
scheduling {
automatic_restart = false
}
}
`, instance)
Expand Down

0 comments on commit 1fea758

Please sign in to comment.