Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scratch_disk property to google_compute_instance and deprecate disk #123

Merged
merged 4 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
limit scope of scratchDisks array by using bool, test formatting
  • Loading branch information
danawillow committed Jun 28, 2017
commit e4b5e183e8cbd7f27f5a85f3cff3912342a2da6b
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