Skip to content

Commit 32e545c

Browse files
sl1pm4tDmitry Vlasov
authored and
Dmitry Vlasov
committed
Fix disk type’Malformed URL’ error (hashicorp#275)
* Fix disk type’Malformed URL’ error The API expects the disk type to be a SelfLink URL, but the disk type name was being used (e.g. “pd-ssd”). * Add ACC Tests for boot disk type * Fix acceptance test & fmt test config The Instance data does not contain the actual disk type, just "PERSISTENT". This commit uses the computeClient to pull the disk data from the API, allowing checking of the disk type. Also fmt'd the test configuration.
1 parent 34e7575 commit 32e545c

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

google/resource_compute_instance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ func expandBootDisk(d *schema.ResourceData, config *Config, zone *compute.Zone,
13751375
if err != nil {
13761376
return nil, fmt.Errorf("Error loading disk type '%s': %s", diskTypeName, err)
13771377
}
1378-
disk.InitializeParams.DiskType = diskType.Name
1378+
disk.InitializeParams.DiskType = diskType.SelfLink
13791379
}
13801380

13811381
if v, ok := d.GetOk("boot_disk.0.initialize_params.0.image"); ok {

google/resource_compute_instance_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,28 @@ func TestAccComputeInstance_bootDisk_source(t *testing.T) {
289289
})
290290
}
291291

292+
func TestAccComputeInstance_bootDisk_type(t *testing.T) {
293+
var instance compute.Instance
294+
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
295+
var diskType = "pd-ssd"
296+
297+
resource.Test(t, resource.TestCase{
298+
PreCheck: func() { testAccPreCheck(t) },
299+
Providers: testAccProviders,
300+
CheckDestroy: testAccCheckComputeInstanceDestroy,
301+
Steps: []resource.TestStep{
302+
resource.TestStep{
303+
Config: testAccComputeInstance_bootDisk_type(instanceName, diskType),
304+
Check: resource.ComposeTestCheckFunc(
305+
testAccCheckComputeInstanceExists(
306+
"google_compute_instance.foobar", &instance),
307+
testAccCheckComputeInstanceBootDiskType(instanceName, diskType),
308+
),
309+
},
310+
},
311+
})
312+
}
313+
292314
func TestAccComputeInstance_noDisk(t *testing.T) {
293315
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
294316

@@ -821,6 +843,23 @@ func testAccCheckComputeInstanceBootDisk(instance *compute.Instance, source stri
821843
}
822844
}
823845

846+
func testAccCheckComputeInstanceBootDiskType(instanceName string, diskType string) resource.TestCheckFunc {
847+
return func(s *terraform.State) error {
848+
config := testAccProvider.Meta().(*Config)
849+
850+
// boot disk is named the same as the Instance
851+
disk, err := config.clientCompute.Disks.Get(config.Project, "us-central1-a", instanceName).Do()
852+
if err != nil {
853+
return err
854+
}
855+
if strings.Contains(disk.Type, diskType) {
856+
return nil
857+
}
858+
859+
return fmt.Errorf("Boot disk not found with type %q", diskType)
860+
}
861+
}
862+
824863
func testAccCheckComputeInstanceScratchDisk(instance *compute.Instance, interfaces []string) resource.TestCheckFunc {
825864
return func(s *terraform.State) error {
826865
if instance.Disks == nil {
@@ -1370,6 +1409,27 @@ resource "google_compute_instance" "foobar" {
13701409
`, disk, instance)
13711410
}
13721411

1412+
func testAccComputeInstance_bootDisk_type(instance string, diskType string) string {
1413+
return fmt.Sprintf(`
1414+
resource "google_compute_instance" "foobar" {
1415+
name = "%s"
1416+
machine_type = "n1-standard-1"
1417+
zone = "us-central1-a"
1418+
1419+
boot_disk {
1420+
initialize_params {
1421+
image = "debian-8-jessie-v20160803"
1422+
type = "%s"
1423+
}
1424+
}
1425+
1426+
network_interface {
1427+
network = "default"
1428+
}
1429+
}
1430+
`, instance, diskType)
1431+
}
1432+
13731433
func testAccComputeInstance_noDisk(instance string) string {
13741434
return fmt.Sprintf(`
13751435
resource "google_compute_instance" "foobar" {

0 commit comments

Comments
 (0)