Skip to content

Fix disk type’Malformed URL’ error #275

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

Merged
merged 3 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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,27 @@ 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))

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

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

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

func testAccCheckComputeInstanceBootDiskType(instance *compute.Instance, diskType string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if instance.Disks == nil {
return fmt.Errorf("no disks")
}

for _, disk := range instance.Disks {
if disk.Boot == true {
if strings.HasSuffix(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) string {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"

boot_disk {
initialize_params {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the indentation here? It should be tabs.

image = "coreos-stable-1409-7-0-v20170719"
type = "pd-ssd"
}
}

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

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