diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 35f4a8efbfe..d6f3b9f1a28 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -55,9 +55,10 @@ func resourceComputeDisk() *schema.Resource { }, "image": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: linkDiffSuppress, }, "project": &schema.Schema{ @@ -78,9 +79,10 @@ func resourceComputeDisk() *schema.Resource { }, "snapshot": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: linkDiffSuppress, }, "type": &schema.Schema{ @@ -261,10 +263,8 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { if disk.DiskEncryptionKey != nil && disk.DiskEncryptionKey.Sha256 != "" { d.Set("disk_encryption_key_sha256", disk.DiskEncryptionKey.Sha256) } - if disk.SourceImage != "" { - imageUrlParts := strings.Split(disk.SourceImage, "/") - d.Set("image", imageUrlParts[len(imageUrlParts)-1]) - } + + d.Set("image", disk.SourceImage) d.Set("snapshot", disk.SourceSnapshot) return nil diff --git a/google/resource_compute_disk_test.go b/google/resource_compute_disk_test.go index 8591a7ea453..eabda37e2ba 100644 --- a/google/resource_compute_disk_test.go +++ b/google/resource_compute_disk_test.go @@ -60,7 +60,7 @@ func TestAccComputeDisk_updateSize(t *testing.T) { }) } -func TestAccComputeDisk_fromSnapshotURI(t *testing.T) { +func TestAccComputeDisk_fromSnapshot(t *testing.T) { diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) firstDiskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) @@ -74,7 +74,14 @@ func TestAccComputeDisk_fromSnapshotURI(t *testing.T) { CheckDestroy: testAccCheckComputeDiskDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccComputeDisk_fromSnapshotURI(firstDiskName, snapshotName, diskName, xpn_host), + Config: testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host, "self_link"), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeDiskExists( + "google_compute_disk.seconddisk", &disk), + ), + }, + resource.TestStep{ + Config: testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host, "name"), Check: resource.ComposeTestCheckFunc( testAccCheckComputeDiskExists( "google_compute_disk.seconddisk", &disk), @@ -251,7 +258,7 @@ resource "google_compute_disk" "foobar" { }`, diskName) } -func testAccComputeDisk_fromSnapshotURI(firstDiskName, snapshotName, diskName, xpn_host string) string { +func testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host string, ref_selector string) string { return fmt.Sprintf(` resource "google_compute_disk" "foobar" { name = "%s" @@ -270,10 +277,10 @@ resource "google_compute_snapshot" "snapdisk" { } resource "google_compute_disk" "seconddisk" { name = "%s" - snapshot = "${google_compute_snapshot.snapdisk.self_link}" + snapshot = "${google_compute_snapshot.snapdisk.%s}" type = "pd-ssd" zone = "us-central1-a" -}`, firstDiskName, xpn_host, snapshotName, xpn_host, diskName) +}`, firstDiskName, xpn_host, snapshotName, xpn_host, diskName, ref_selector) } func testAccComputeDisk_encryption(diskName string) string {