From 4c4b4be413eb7af5689329ef16d16c54394b49d1 Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Wed, 9 May 2018 10:59:48 -0700 Subject: [PATCH] When a disk shrinks, require ForceNew. (#1460) --- google/resource_compute_disk.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 37cab84b..9bab6c84 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform/helper/customdiff" "github.com/hashicorp/terraform/helper/schema" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" @@ -118,6 +119,8 @@ func resourceComputeDisk() *schema.Resource { Computed: true, }, }, + CustomizeDiff: customdiff.All( + customdiff.ForceNewIfChange("size", isDiskShrinkage)), } } @@ -410,6 +413,15 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error { return nil } +// Is the new disk size smaller than the old one? +func isDiskShrinkage(old, new, _ interface{}) bool { + // It's okay to remove size entirely. + if old == nil || new == nil { + return false + } + return new.(int) < old.(int) +} + // We cannot suppress the diff for the case when family name is not part of the image name since we can't // make a network call in a DiffSuppressFunc. func diskImageDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {