Skip to content

Commit

Permalink
Merge pull request #238 from z1nkum/snapshot-fix-url-to-name
Browse files Browse the repository at this point in the history
Fix google_compute_disk created from snapshot, forces new resource then apply once more
  • Loading branch information
paddycarver authored Aug 15, 2017
2 parents eca4c3e + d0b7fbc commit f792923
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
20 changes: 10 additions & 10 deletions google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions google/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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),
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down

0 comments on commit f792923

Please sign in to comment.