Skip to content

Commit 8db8607

Browse files
authored
google_compute_instance reads scheduling fields from GCP. (hashicorp#237)
1 parent 483febd commit 8db8607

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

google/resource_compute_instance.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,28 @@ func resourceComputeInstance() *schema.Resource {
378378

379379
"scheduling": &schema.Schema{
380380
Type: schema.TypeList,
381+
MaxItems: 1,
381382
Optional: true,
383+
Computed: true,
382384
Elem: &schema.Resource{
383385
Schema: map[string]*schema.Schema{
384386
"on_host_maintenance": &schema.Schema{
385387
Type: schema.TypeString,
386388
Optional: true,
389+
Computed: true,
387390
},
388391

389392
"automatic_restart": &schema.Schema{
390393
Type: schema.TypeBool,
391394
Optional: true,
395+
Default: true,
392396
},
393397

394398
"preemptible": &schema.Schema{
395399
Type: schema.TypeBool,
396400
Optional: true,
401+
Default: false,
402+
ForceNew: true,
397403
},
398404
},
399405
},
@@ -787,6 +793,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
787793
if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok {
788794
scheduling.OnHostMaintenance = val.(string)
789795
}
796+
scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"}
790797

791798
// Read create timeout
792799
var createTimeout int
@@ -1060,6 +1067,9 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
10601067
d.Set("attached_disk", attachedDisks)
10611068
d.Set("scratch_disk", scratchDisks)
10621069

1070+
scheduling, _ := flattenScheduling(instance.Scheduling)
1071+
d.Set("scheduling", scheduling)
1072+
10631073
d.Set("self_link", instance.SelfLink)
10641074
d.SetId(instance.Name)
10651075

@@ -1168,14 +1178,13 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
11681178
if val, ok := d.GetOk(prefix + ".automatic_restart"); ok {
11691179
scheduling.AutomaticRestart = googleapi.Bool(val.(bool))
11701180
}
1171-
11721181
if val, ok := d.GetOk(prefix + ".preemptible"); ok {
11731182
scheduling.Preemptible = val.(bool)
11741183
}
1175-
11761184
if val, ok := d.GetOk(prefix + ".on_host_maintenance"); ok {
11771185
scheduling.OnHostMaintenance = val.(string)
11781186
}
1187+
scheduling.ForceSendFields = []string{"AutomaticRestart", "Preemptible"}
11791188

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

0 commit comments

Comments
 (0)