From 63f76107a86c8fe91b7ec2ef4016d11e80351be1 Mon Sep 17 00:00:00 2001 From: Dmitry Vlasov Date: Tue, 25 Jul 2017 19:13:26 +0300 Subject: [PATCH 1/4] fix issue #218 --- google/resource_compute_disk.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 7b7d564372f..12d84ce8632 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -265,7 +265,11 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { imageUrlParts := strings.Split(disk.SourceImage, "/") d.Set("image", imageUrlParts[len(imageUrlParts)-1]) } - d.Set("snapshot", disk.SourceSnapshot) + + if disk.SourceSnapshot != "" { + snapshotUrlParts := strings.Split(disk.SourceSnapshot, "/") + d.Set("snapshot", snapshotUrlParts[len(snapshotUrlParts)-1]) + } return nil } From 9950c6d1d066c74a94e44d12504ec87ed82b2f90 Mon Sep 17 00:00:00 2001 From: Dmitry Vlasov Date: Sat, 5 Aug 2017 22:39:30 +0300 Subject: [PATCH 2/4] change request, use DiffSuppressFunc for image and snapshot properties --- google/resource_compute_disk.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 12d84ce8632..816c8e7de41 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -58,6 +58,7 @@ func resourceComputeDisk() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + DiffSuppressFunc: linkDiffSuppress, }, "project": &schema.Schema{ @@ -81,6 +82,7 @@ func resourceComputeDisk() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + DiffSuppressFunc: linkDiffSuppress, }, "type": &schema.Schema{ @@ -261,15 +263,9 @@ 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]) - } - if disk.SourceSnapshot != "" { - snapshotUrlParts := strings.Split(disk.SourceSnapshot, "/") - d.Set("snapshot", snapshotUrlParts[len(snapshotUrlParts)-1]) - } + d.Set("image", disk.SourceImage) + d.Set("snapshot", disk.SourceSnapshot) return nil } From 2f5ad2492befc59c85a7f5657d779c8c676a2423 Mon Sep 17 00:00:00 2001 From: Dmitry Vlasov Date: Sat, 5 Aug 2017 22:45:20 +0300 Subject: [PATCH 3/4] change request, use DiffSuppressFunc for image and snapshot properties (+fmt) --- google/resource_compute_disk.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 816c8e7de41..218e45d8c78 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -55,9 +55,9 @@ func resourceComputeDisk() *schema.Resource { }, "image": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, DiffSuppressFunc: linkDiffSuppress, }, @@ -79,9 +79,9 @@ func resourceComputeDisk() *schema.Resource { }, "snapshot": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, DiffSuppressFunc: linkDiffSuppress, }, From d0b7fbc12f990e0436a8c139cecca5992f98dd97 Mon Sep 17 00:00:00 2001 From: Dmitry Vlasov Date: Sat, 12 Aug 2017 21:47:18 +0300 Subject: [PATCH 4/4] update snapshot test (add case with name reference) --- google/resource_compute_disk_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 {