When a disk shrinks, require ForceNew. (#1460)

This commit is contained in:
Nathan McKinley 2018-05-09 10:59:48 -07:00 committed by GitHub
parent 04a475d73d
commit 4c4b4be413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {