Skip to content

Commit

Permalink
Test update to ensure that encryption works right.
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-henderson committed May 31, 2018
1 parent 3bbc975 commit 4073b32
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions google/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ func TestAccComputeDisk_encryption(t *testing.T) {
"google_compute_disk.foobar", &disk),
),
},
// Update from top-level attribute to nested.
resource.TestStep{
Config: testAccComputeDisk_encryptionMigrate(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
testAccCheckEncryptionKey(
"google_compute_disk.foobar", &disk),
),
},
// Update from nested attribute back to top-level.
resource.TestStep{
Config: testAccComputeDisk_encryption(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
testAccCheckEncryptionKey(
"google_compute_disk.foobar", &disk),
),
},
},
})
}
Expand Down Expand Up @@ -548,9 +568,7 @@ func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckF
attr := rs.Primary.Attributes["disk_encryption_key_sha256"]
if disk.DiskEncryptionKey == nil && attr != "" {
return fmt.Errorf("Disk %s has mismatched encryption key.\nTF State: %+v\nGCP State: <empty>", n, attr)
}

if attr != disk.DiskEncryptionKey.Sha256 {
} else if disk.DiskEncryptionKey != nil && attr != disk.DiskEncryptionKey.Sha256 {
return fmt.Errorf("Disk %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
n, attr, disk.DiskEncryptionKey.Sha256)
}
Expand Down Expand Up @@ -662,6 +680,20 @@ resource "google_compute_disk" "foobar" {
}`, diskName)
}

func testAccComputeDisk_encryptionMigrate(diskName string) string {
return fmt.Sprintf(`
resource "google_compute_disk" "foobar" {
name = "%s"
image = "debian-8-jessie-v20160803"
size = 50
type = "pd-ssd"
zone = "us-central1-a"
disk_encryption_key {
raw_key = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0="
}
}`, diskName)
}

func testAccComputeDisk_deleteDetach(instanceName, diskName string) string {
return fmt.Sprintf(`
resource "google_compute_disk" "foo" {
Expand Down

0 comments on commit 4073b32

Please sign in to comment.