Skip to content
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

Fix google_compute_disk created from snapshot, forces new resource then apply once more #238

Merged
merged 4 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
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