diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 2580b0f2..140686cc 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -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) diff --git a/google/resource_compute_disk_test.go b/google/resource_compute_disk_test.go index b5525459..5ae0f430 100644 --- a/google/resource_compute_disk_test.go +++ b/google/resource_compute_disk_test.go @@ -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: ", 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) }