Skip to content

Commit

Permalink
limit scope of bootDisk, use bool instead
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed Jun 16, 2017
1 parent e0f0d38 commit 63d9f0b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
// Build up the list of disks

disks := []*compute.AttachedDisk{}
var bootDisk *compute.AttachedDisk
if _, ok := d.GetOk("boot_disk"); ok {
bootDisk, err = expandBootDisk(d, config, zone, project)
var hasBootDisk bool
if _, hasBootDisk = d.GetOk("boot_disk"); hasBootDisk {
bootDisk, err := expandBootDisk(d, config, zone, project)
if err != nil {
return err
}
Expand All @@ -483,7 +483,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
disksCount := d.Get("disk.#").(int)
attachedDisksCount := d.Get("attached_disk.#").(int)

if disksCount+attachedDisksCount == 0 && bootDisk == nil {
if disksCount+attachedDisksCount == 0 && !hasBootDisk {
return fmt.Errorf("At least one disk, attached_disk, or boot_disk must be set")
}
for i := 0; i < disksCount; i++ {
Expand All @@ -495,7 +495,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
var disk compute.AttachedDisk
disk.Type = "PERSISTENT"
disk.Mode = "READ_WRITE"
disk.Boot = i == 0 && bootDisk == nil
disk.Boot = i == 0 && !hasBootDisk
disk.AutoDelete = d.Get(prefix + ".auto_delete").(bool)

if _, ok := d.GetOk(prefix + ".disk"); ok {
Expand Down Expand Up @@ -586,7 +586,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
AutoDelete: false, // Don't allow autodelete; let terraform handle disk deletion
}

disk.Boot = i == 0 && disksCount == 0 && bootDisk == nil
disk.Boot = i == 0 && disksCount == 0 && !hasBootDisk

if v, ok := d.GetOk(prefix + ".device_name"); ok {
disk.DeviceName = v.(string)
Expand Down

0 comments on commit 63d9f0b

Please sign in to comment.