Skip to content

Commit 4ffdec8

Browse files
danawillowmodular-magician
authored andcommitted
send scheduling block with automaticrestart if there is none in cfg
1 parent ecaa5eb commit 4ffdec8

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

google/resource_compute_instance.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,22 @@ func expandComputeInstance(project string, zone *compute.Zone, d *schema.Resourc
625625
disks = append(disks, disk)
626626
}
627627

628-
prefix := "scheduling.0"
629-
scheduling := &computeBeta.Scheduling{
630-
AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)),
631-
Preemptible: d.Get(prefix + ".preemptible").(bool),
632-
OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string),
633-
ForceSendFields: []string{"AutomaticRestart", "Preemptible"},
628+
sch := d.Get("scheduling").([]interface{})
629+
var scheduling *computeBeta.Scheduling
630+
if len(sch) == 0 {
631+
// TF doesn't do anything about defaults inside of nested objects, so if
632+
// scheduling hasn't been set, then send it with its default values.
633+
scheduling = &computeBeta.Scheduling{
634+
AutomaticRestart: googleapi.Bool(true),
635+
}
636+
} else {
637+
prefix := "scheduling.0"
638+
scheduling = &computeBeta.Scheduling{
639+
AutomaticRestart: googleapi.Bool(d.Get(prefix + ".automatic_restart").(bool)),
640+
Preemptible: d.Get(prefix + ".preemptible").(bool),
641+
OnHostMaintenance: d.Get(prefix + ".on_host_maintenance").(string),
642+
ForceSendFields: []string{"AutomaticRestart", "Preemptible"},
643+
}
634644
}
635645

636646
metadata, err := resourceInstanceMetadata(d)

0 commit comments

Comments
 (0)