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

Fix disk type’Malformed URL’ error #275

Merged
merged 3 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ func expandBootDisk(d *schema.ResourceData, config *Config, zone *compute.Zone,
if err != nil {
return nil, fmt.Errorf("Error loading disk type '%s': %s", diskTypeName, err)
}
disk.InitializeParams.DiskType = diskType.Name
disk.InitializeParams.DiskType = diskType.SelfLink
}

if v, ok := d.GetOk("boot_disk.0.initialize_params.0.image"); ok {
Expand Down
60 changes: 60 additions & 0 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ func TestAccComputeInstance_bootDisk_source(t *testing.T) {
})
}

func TestAccComputeInstance_bootDisk_type(t *testing.T) {
var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
var diskType = "pd-ssd"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeInstance_bootDisk_type(instanceName, diskType),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceBootDiskType(instanceName, diskType),
),
},
},
})
}

func TestAccComputeInstance_noDisk(t *testing.T) {
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))

Expand Down Expand Up @@ -821,6 +843,23 @@ func testAccCheckComputeInstanceBootDisk(instance *compute.Instance, source stri
}
}

func testAccCheckComputeInstanceBootDiskType(instanceName string, diskType string) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

// boot disk is named the same as the Instance
disk, err := config.clientCompute.Disks.Get(config.Project, "us-central1-a", instanceName).Do()
if err != nil {
return err
}
if strings.Contains(disk.Type, diskType) {
return nil
}

return fmt.Errorf("Boot disk not found with type %q", diskType)
}
}

func testAccCheckComputeInstanceScratchDisk(instance *compute.Instance, interfaces []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if instance.Disks == nil {
Expand Down Expand Up @@ -1370,6 +1409,27 @@ resource "google_compute_instance" "foobar" {
`, disk, instance)
}

func testAccComputeInstance_bootDisk_type(instance string, diskType string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = "debian-8-jessie-v20160803"
type = "%s"
}
}

network_interface {
network = "default"
}
}
`, instance, diskType)
}

func testAccComputeInstance_noDisk(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
Expand Down