Correct issue with Disk encryption. (#1584)

* Correct issue with Disk encryption.

* Update to test to make it less permissive.
This commit is contained in:
The Magician 2018-06-04 10:01:52 -07:00 committed by Vincent Roseberry
parent dd92a3732e
commit b85473619c
2 changed files with 5 additions and 5 deletions

View File

@ -236,10 +236,10 @@ func diskEncryptionKeyDiffSuppress(k, old, new string, d *schema.ResourceData) b
}
} else if strings.HasSuffix(k, "raw_key") {
disk_key := d.Get("disk_encryption_key_raw").(string)
return disk_key == old
return disk_key == old && old != "" && new == ""
} else if k == "disk_encryption_key_raw" {
disk_key := d.Get("disk_encryption_key.0.raw_key").(string)
return disk_key == old
return disk_key == old && old != "" && new == ""
}
return false
}
@ -1004,7 +1004,7 @@ func expandComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData, c
req = append(req, outMap)
} else {
// Check alternative setting?
if altV, ok := d.GetOk("disk_encryption_key_raw"); ok {
if altV, ok := d.GetOk("disk_encryption_key_raw"); ok && altV != "" {
outMap := make(map[string]interface{})
outMap["rawKey"] = altV
req = append(req, outMap)

View File

@ -566,9 +566,9 @@ func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckF
}
attr := rs.Primary.Attributes["disk_encryption_key_sha256"]
if disk.DiskEncryptionKey == nil && attr != "" {
if disk.DiskEncryptionKey == nil {
return fmt.Errorf("Disk %s has mismatched encryption key.\nTF State: %+v\nGCP State: <empty>", n, attr)
} else if disk.DiskEncryptionKey != nil && attr != disk.DiskEncryptionKey.Sha256 {
} else if attr != disk.DiskEncryptionKey.Sha256 {
return fmt.Errorf("Disk %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v",
n, attr, disk.DiskEncryptionKey.Sha256)
}