Skip to content

Commit

Permalink
limit scope of scratchDisks array by using bool, test formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed Jun 28, 2017
1 parent 3e19f48 commit e4b5e18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
8 changes: 4 additions & 4 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
disks = append(disks, bootDisk)
}

scratchDisks := []*compute.AttachedDisk{}
if _, ok := d.GetOk("scratch_disk"); ok {
scratchDisks, err = expandScratchDisks(d, config, zone)
var hasScratchDisk bool
if _, hasScratchDisk := d.GetOk("scratch_disk"); hasScratchDisk {
scratchDisks, err := expandScratchDisks(d, config, zone)
if err != nil {
return err
}
Expand Down Expand Up @@ -571,7 +571,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err

if v, ok := d.GetOk(prefix + ".scratch"); ok {
if v.(bool) {
if len(scratchDisks) > 0 {
if hasScratchDisk {
return fmt.Errorf("Cannot set scratch disks using both `scratch_disk` and `disk` properties")
}
disk.Type = "SCRATCH"
Expand Down
39 changes: 20 additions & 19 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,30 +1431,31 @@ resource "google_compute_instance" "local-ssd" {

func testAccComputeInstance_scratchDisk(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "scratch" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-8-jessie-v20160803"
}
}
resource "google_compute_instance" "scratch" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
scratch_disk {
interface = "NVME"
boot_disk {
initialize_params {
image = "debian-8-jessie-v20160803"
}
}
scratch_disk {
interface = "SCSI"
}
scratch_disk {
interface = "NVME"
}
network_interface {
network = "default"
}
scratch_disk {
interface = "SCSI"
}
}`, instance)
network_interface {
network = "default"
}
}
`, instance)
}

func testAccComputeInstance_service_account(instance string) string {
Expand Down

0 comments on commit e4b5e18

Please sign in to comment.